Sure. Thanks for your help.
private void Form1_Load(obje ct sender, EventArgs e)
{
ConnectionOptio ns co = new ConnectionOptio ns();
co.Impersonatio n = ImpersonationLe vel.Impersonate ;
co.EnablePrivil eges = true;
co.Username = "User";
co.Password = "password";
ManagementScope myscope = new
ManagementScope (@"\\Computerna me\ROOT\CIMV2", co);
myscope.Connect ();
ManagementClass myclass = new ManagementClass (myscope, new
ManagementPath( "Win32_Process" ), new ObjectGetOption s(null,
TimeSpan.MaxVal ue, true));
ManagementBaseO bject inparams =
myclass.GetMeth odParameters("C reate");
inparams["CommandLin e"] = @"calc.exe";
InvokeMethodOpt ions MethodOptions = new
InvokeMethodOpt ions(null, System.TimeSpan .MaxValue);
ManagementBaseO bject outparams = myclass.InvokeM ethod("Create",
inparams, MethodOptions);
string ProcID = outparams["ProcessID"].ToString();
string retval = outparams["ReturnValu e"].ToString();
WqlEventQuery wQuery = new WqlEventQuery(" Select * From
__InstanceDelet ionEvent Within 1 Where TargetInstance ISA 'Win32_Process' ");
ManagementEvent Watcher wWatcher = new
ManagementEvent Watcher(myscope , wQuery);
int i = 1;
while (i == 1)
{
ManagementBaseO bject MBOobj = wWatcher.WaitFo rNextEvent();
if
(((ManagementBa seObject)MBOobj["TargetInstance "])["ProcessID"].ToString() ==
ProcID)
{
//MessageBox.Show (retval+ " - " +
((ManagementBas eObject)MBOobj["TargetInstance "])["Name"].ToString() + " - " +
((ManagementBas eObject)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.co m
"Suresh Nagarajan" <Su************ *@discussions.m icrosoft.comwro te in
message news:C2******** *************** ***********@mic rosoft.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
InvokeMethodOpt ions MethodOptions = new InvokeMethodOpt ions(null,
System.TimeSpan .MaxValue);
And
ManagementEvent Watcher for completion of the applicaiton.
Thanks,
Suresh