473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Start Remote Process and track the exit code

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

Apr 4 '07 #1
4 5494
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

Apr 4 '07 #2
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


Apr 5 '07 #3
"Suresh Nagarajan" <Su************ *@discussions.m icrosoft.comwro te in message
news:9A******** *************** ***********@mic rosoft.com...
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



You can't get the "exit code" on anything less than Vista and Longhorn,
So the following only works on Vista, on XP you get the exit event but without the
ExitStatus property.

......
WqlEventQuery q = new WqlEventQuery( "Win32_ProcessS topTrace");
using(Managemen tEventWatcher w = new ManagementEvent Watcher(q)){
w.EventArrived += new EventArrivedEve ntHandler(Proce ssStoptEventArr ived);
w.Start();
Console.ReadLin e(); // block main thread for test purposes
w.Stop();
}
}
static void ProcessStoptEve ntArrived(objec t sender, EventArrivedEve ntArgs e) {

Console.WriteLi ne("Process : {0}, stopped with ExitStatus :{1},
Console.WriteLi ne("Process: {0}, Stopped with Code: {1}",
(int)(uint)e.Ne wEvent.Properti es["ProcessId"].Value,
(int)(uint)e.Ne wEvent.Properti es["ExitStatus "].Value);

}
....

Willy.

Apr 6 '07 #4
Hi Willy,
Thanks for your response. I came across .NET Remoting. without looking
deep into it, wanted to know if this is something that I could use to get the
same results.

Please forgive my ignorance. I am a newbie to C#.

Thanks,
Suresh

"Willy Denoyette [MVP]" wrote:
"Suresh Nagarajan" <Su************ *@discussions.m icrosoft.comwro te in message
news:9A******** *************** ***********@mic rosoft.com...
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



You can't get the "exit code" on anything less than Vista and Longhorn,
So the following only works on Vista, on XP you get the exit event but without the
ExitStatus property.

......
WqlEventQuery q = new WqlEventQuery( "Win32_ProcessS topTrace");
using(Managemen tEventWatcher w = new ManagementEvent Watcher(q)){
w.EventArrived += new EventArrivedEve ntHandler(Proce ssStoptEventArr ived);
w.Start();
Console.ReadLin e(); // block main thread for test purposes
w.Stop();
}
}
static void ProcessStoptEve ntArrived(objec t sender, EventArrivedEve ntArgs e) {

Console.WriteLi ne("Process : {0}, stopped with ExitStatus :{1},
Console.WriteLi ne("Process: {0}, Stopped with Code: {1}",
(int)(uint)e.Ne wEvent.Properti es["ProcessId"].Value,
(int)(uint)e.Ne wEvent.Properti es["ExitStatus "].Value);

}
....

Willy.

Apr 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2601
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
2
3206
by: Tobias Johansson | last post by:
Hello, I'm having what I believe a security problem to execute an executable file from a windows service in windows server 2003. It works fine in WIN XP SP2 The program(the service) itself just continues as if nothing where wrong after process.Start is executed and I get an Exit code from the process
10
15918
by: Tony | last post by:
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is that AcroComm will sometimes stop polling in the middle of the process and terminate. The programing manual for the app says that it sends a code to the operating system when it is done that tells what has happend like the following: 0 ...
14
7241
by: Jasonkimberson | last post by:
Currently I am having a problem creating a windows service that monitors a mapped drive for events (using the FileSystemEventHandler). The service complies but fails to start: "The XMLWatcher service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Preformance Logs and Alerts service." The Service has no problem starting if i point the folder to be monitored to...
16
4223
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the project in debug mode (by hitting F5) it gives an error message "Error while trying to run project: Unable to start debugging on the web server.
2
4142
by: Greg Allen | last post by:
I know this has been discussed before, and have found some documentation about it on the web. But nothing has fixed my problem. I am running the 1.1 .NET framework, SP1. I have a web application that I would like to place on a remote shared drive on a different computer. I had problems with that, so I simplified it so that I am trying to use a shared drive on the SAME computer. That doesn't work
10
1978
by: Doug Robertson | last post by:
First off, I'm a hardware/OS guy. I just write code on the side and I'm completely self taught - so bear in mind my total lack of expertise. I have a program originally written in VB2003 using the dotnet 1.1 framework. The program makes extensive use of Win32 API calls to help manage and track remote access sessions with out clients. I've left it running for days at a time on my system with no problems. It has always been stable. I...
3
9468
by: Billy Bob | last post by:
Hello In C# how can i start a remote process such as someapp.exe on a remote PC? I know the remote PC's name, but how do I start the app on that PC? Thanks ..
5
4808
by: sjoshi23 | last post by:
Hello I'm trying to start a remote desktop session using Process.Start but it keeps saying "File not found". The same cmd thru DOS window works fine. I used: C:\\WINDOWS\\system32\\mstsc.exe /v:SP3DLAB4 Any hints ?
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.