Sure. Thanks for your help.
private void Form1_Load(object sender, EventArgs e)
{
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.EnablePrivileges = true;
co.Username = "User";
co.Password = "password";
ManagementScope myscope = new
ManagementScope(@"\\Computername\ROOT\CIMV2", co);
myscope.Connect();
ManagementClass myclass = new ManagementClass(myscope, new
ManagementPath("Win32_Process"), new ObjectGetOptions(null,
TimeSpan.MaxValue, true));
ManagementBaseObject inparams =
myclass.GetMethodParameters("Create");
inparams["CommandLine"] = @"calc.exe";
InvokeMethodOptions MethodOptions = new
InvokeMethodOptions(null, System.TimeSpan.MaxValue);
ManagementBaseObject outparams = myclass.InvokeMethod("Create",
inparams, MethodOptions);
string ProcID = outparams["ProcessID"].ToString();
string retval = outparams["ReturnValue"].ToString();
WqlEventQuery wQuery = new WqlEventQuery("Select * From
__InstanceDeletionEvent Within 1 Where TargetInstance ISA 'Win32_Process'");
ManagementEventWatcher wWatcher = new
ManagementEventWatcher(myscope, wQuery);
int i = 1;
while (i == 1)
{
ManagementBaseObject MBOobj = wWatcher.WaitForNextEvent();
if
(((ManagementBaseObject)MBOobj["TargetInstance"])["ProcessID"].ToString() ==
ProcID)
{
//MessageBox.Show(retval+ " - " +
((ManagementBaseObject)MBOobj["TargetInstance"])["Name"].ToString() + " - " +
((ManagementBaseObject)MBOobj["TargetInstance"])["ExecutablePath"].ToString()); ;
i = 5;
}
}
wWatcher.Stop();
}
"Nicholas Paldino [.NET/C# MVP]" wrote:
Suresh,
Can you show some code how you are starting the process in the first
place?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Suresh Nagarajan" <Su*************@discussions.microsoft.comwrote in
message news:C2**********************************@microsof t.com...
Hello,
I am trying to execute an application on a remote system. After checking
several of the website I was managed to write a C# application do the
same.
But I am not able to track the Exit Code of the application. The return
value only tells me if the application started successfully.
Is their a way to capture the final exit code of the application that is
started remotely?
using Invoke Method
InvokeMethodOptions MethodOptions = new InvokeMethodOptions(null,
System.TimeSpan.MaxValue);
And
ManagementEventWatcher for completion of the applicaiton.
Thanks,
Suresh