Sreenath G

Sreenath G

  • NA
  • 233
  • 244.4k

Scheduling Job Through ASP.Net programming is failing

Mar 15 2011 11:01 PM
 

I'm trying to create a Scheduled job in windows machine. I am doing this:

     private static uint mFnCreateJob(string Command, uint DaysOfMonth, uint DaysOfWeek, bool InteractWithDesktop, bool RunRepeatedly, string StartTime, out uint JobId)

        {

 

            try

            {

                ManagementBaseObject lObjInputArgs = null;

                ManagementScope lObjScope = new ManagementScope(@"\root\cimv2");

 

                lObjScope.Connect();

 

                ManagementClass lObjclassObj = new ManagementClass(lObjScope, new ManagementPath("Win32_ScheduledJob"), null);

 

                lObjInputArgs = lObjclassObj.GetMethodParameters("Create");

 

                lObjInputArgs["Command"] = Command;

                lObjInputArgs["DaysOfMonth"] = DaysOfMonth;

                lObjInputArgs["DaysOfWeek"] = DaysOfWeek;

                lObjInputArgs["InteractWithDesktop"] = InteractWithDesktop;

                lObjInputArgs["RunRepeatedly"] = RunRepeatedly;

                lObjInputArgs["StartTime"] = StartTime;

 

                ManagementBaseObject outParams = lObjclassObj.InvokeMethod("Create", lObjInputArgs, null);

 

                JobId = ((uint)(outParams.Properties["JobId"].Value));

 

                return ((uint)(outParams.Properties["ReturnValue"].Value));

 

            }

            catch (Exception ex)

            {

 

                throw ex;

            }

        }

 

..and it always fails. The outParams["ReturnValue "] is 2 and is null outParams.Properties["JobId"].Value…like fails. Any suggestions on this please.

Thanks

Sreenath                        


Answers (1)