WMI Scheduled Task running under system user in windows 7 not showing GUI instead running in back gr

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
We have scheduled a task through WMI to invoke an exe in remote machine which has a GUI. It was running perfectly in windows XP, but facing problem in windows 7. The process is running fine and the invocation of the exe is ok but the GUI is not opening.
Only the process is listed in the task manager and running as a back ground task. GUI is a .NET form. The code snippet has been given below for reference. While the schedule task is invoking the process it is running under system account of the remote machine.
I have tried to create another schedule task through the Task Scheduler provided with windows 7 and realise if we use the same user through which we have logged in to the system to run the process there is not problem of showing the GUI, but if we change
the user to run the process as "system" the same problem is happning. Unfortunately we cant specify the user account under which the schedule task will run at the time of creating the Schedule Task through WMI. Please help.
<pre class="prettyprint //Remote PC Connection with Admin Credentials
ConnectionOptions options = new ConnectionOptions();
//options.Username = ConfigurationSettings.AppSettings["UserName"];
//options.Password = FDS.Encryption.DESCryptoHelper.Decrypt(ConfigurationSettings.AppSettings["Password"]);
//options.Authority = "ntlmdomain:" + registerIp;
options.Impersonation = ImpersonationLevel.Impersonate;
options.EnablePrivileges = true;
options.Username = registerIp + "\" + ConfigurationSettings.AppSettings["UserName"];
options.Password = FDS.Encryption.DESCryptoHelper.Decrypt(ConfigurationSettings.AppSettings["Password"]);
ManagementScope scope = new ManagementScope("\\" + registerIp + "\root\cimv2", options);
//Get Remote Register TimeStamp
DateTime remoteRegisterDateTime = DateTime.Now;
scope.Connect();
SelectQuery selectQuery = new SelectQuery("select * from win32_localtime");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, selectQuery);
foreach (ManagementObject mo in searcher.Get())
{
remoteRegisterDateTime = new DateTime(
Convert.ToInt32(mo["Year"]),
Convert.ToInt32(mo["Month"]),
Convert.ToInt32(mo["Day"]),
Convert.ToInt32(mo["Hour"]),
Convert.ToInt32(mo["Minute"]),
Convert.ToInt32(mo["Second"]),
Convert.ToInt32(mo["Milliseconds"]));
}
ManagementBaseObject inputArgs = null;
System.Management.ManagementPath mPath = new ManagementPath("Win32_ScheduledJob");
ManagementClass classObj = new ManagementClass(scope, mPath, null);
inputArgs = classObj.GetMethodParameters("Create");
inputArgs["Command"] = """ + ConfigurationSettings.AppSettings["RemoteProgramToRun"] + """;
//inputArgs["StartTime"] = ToDMTFTime(remoteRegisterDateTime.AddMinutes(1));
if (DateTime.Now.Second >= 40)
inputArgs["StartTime"] = ToDMTFTime(DateTime.Now.AddMinutes(2));
else
inputArgs["StartTime"] = ToDMTFTime(DateTime.Now.AddMinutes(1));
inputArgs["InteractWithDesktop"] = true;
ManagementBaseObject outParams = classObj.InvokeMethod("Create", inputArgs, null);
FDLogger.LogInfo(Environment.MachineName + " - Successfully started FDSPOSMessage in Register : " + registerIp);
uint jobId = (uint)outParams["JobId"];[/code]
<br/>


View the full article
 
Back
Top