How to start another program in Windows Service?

D

Dao

I have created a windows service called MyService. I followed the MSDN sample code to add the following code but it did not work. What I tried was that to start another or external program when MyService starts. I used notepad.exe as an example of a program to be called when MyService starts. I have tried both in the InitializationComponenet() then in the OnStart() Method but none of them work. Any help would be appreciated.

private void InitializeComponent()
{
this.process1 = new System.Diagnostics.Process();
//
// process1
//
this.process1.StartInfo.FileName = "c:\\WINDOWS\\notepad.exe";
this.ServiceName = "MyService";
}

I also tried this:

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "c:\\windows\\notepad.exe";
}





From http://www.developmentnow.com/g/36_2005_4_0_17_0/dotnet-languages-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
W

Wayne

Who is the service running as? if it's running as the system you will not
see the other application start. Open the task manager and see if you see
Notepad.exe running as the system.


--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

Dao said:
I have created a windows service called MyService. I followed the MSDN
sample code to add the following code but it did not work. What I tried was
that to start another or external program when MyService starts. I used
notepad.exe as an example of a program to be called when MyService starts.
I have tried both in the InitializationComponenet() then in the OnStart()
Method but none of them work. Any help would be appreciated.
private void InitializeComponent()
{
this.process1 = new System.Diagnostics.Process();
//
// process1
//
this.process1.StartInfo.FileName = "c:\\WINDOWS\\notepad.exe";
this.ServiceName = "MyService";
}

I also tried this:

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "c:\\windows\\notepad.exe";
}





From http://www.developmentnow.com/g/36_2005_4_0_17_0/dotnet-languages-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 
H

H Dao

I have set in the ServiceProjectInstaller's Account property as
LocalSystem. I also looked at Service Manager window to monitor but did
not see it.

Thanks,
HD
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

The problem you have is that notepad is an interactive program,.the service
do not have a "display" where to show the notepad window, remember that the
service is running even if nobody is logged on the computer
The same thing happen when you are starting the service, if you have it
declared as "automatic" it's started when windows is starting, at that
moment you still have the windows startup screen.

cheers,
 
H

H Dao

In addition to my previous reply. I did see MyService.exe in Windows's
Task Manager but not the notepad.exe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top