starting another process from a c# service

  • Thread starter Thread starter sumant
  • Start date Start date
S

sumant

Hi
I want to start another process from a c# program running as a windows
service.
So in the procedure onstart
I have said something like this

process p= new process();
p.Startinfo.filename="abc.bat";
p.Start();

The problem is if I run the .bat file alone it runs fine ,but when i
call it from a c# service I dont know
a)where exactly it goes wrong...is there someway i can capture the
output of the bat file?

since i am running as a service the normal command window which pops
up also doesnt show.

the same thing if i run it as a normal console application then the
bat file goes along fine..

Could some one help me out on this?
Many thanks
Sumant
 
Services are run in a different desktop than the interactive one. That is
the reason why you dont see the application come up.
To start it up, you can still do the same what you are doing and use some
sort of console redirect (Using RedirectStandardOutput in combination with
StandardOutput in ProcessStartInfo) to get the output from the bat file. Or
you can make the bat file write to a file and use the Process handle to wait
until done (although I am not sure if Console window follow the same rules
as regular windows).
 
Hi Sumant!

I want to start another process from a c# program running as a windows
service.
So in the procedure onstart
I have said something like this

process p= new process();
p.Startinfo.filename="abc.bat";
p.Start();

The problem is if I run the .bat file alone it runs fine ,but when i
call it from a c# service I dont know
a)where exactly it goes wrong...is there someway i can capture the
output of the bat file?

since i am running as a service the normal command window which pops
up also doesnt show.

the same thing if i run it as a normal console application then the
bat file goes along fine..

For more info about services and desktops:

http://support.microsoft.com/?kbid=171890
http://support.microsoft.com/?kbid327618
http://support.microsoft.com/?kbid=165194
http://www.microsoft.com/msj/0398/service2.htm
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconIntroductionToNTServiceApplications.asp

Each service has an associated window station and desktop is
called Interactive Service. You may take the following steps to change your
service's logon to LocalSystem and then allow interaction with desktop.

1. Open Control Panel -> Administration Tools -> Services
2. Find your service and right click it and select Properties
3. Select the Log On tab
4. Select Log on as Local System account and check the box before allow
service to interact with desktop

Cheers

Arne Janning
 
Back
Top