473,511 Members | 14,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to start another program in Windows Service?

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_2...ges-csharp.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 17 '05 #1
4 18994
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" <hu******@yahoo.com> wrote in message
news:c1**********************************@msnews.m icrosoft.com...
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_2...ges-csharp.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Nov 17 '05 #2
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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dao" <hu******@yahoo.com> wrote in message
news:c1**********************************@msnews.m icrosoft.com...
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_2...ges-csharp.htm

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

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

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5

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

Similar topics

2
21855
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be...
2
3183
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...
12
4078
by: GTi | last post by:
I have small program that always must be running when a user is logged on. Since users can close this program I must create a program that always check if this program is running. So I created a...
5
13408
by: SiD` | last post by:
when starting a windows service writte in vb.net, a messagebox appears: cannot start service from the command line or a debugger. A windows service must first be installed using installutil.exe ...
6
4152
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
17
6413
by: UJ | last post by:
Is there any way for a windows service to start a windows program ? I have a service that will need to restart a windows app if it needs to. TIA - Jeff.
3
6128
by: illegal.prime | last post by:
Hi all, I have a service that needs to start a regular windows application. I'm running the service as ServiceAccount.LocalSystem. But, when it starts the process (using Process.Start) the GUI...
4
21685
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
2
9447
by: =?Utf-8?B?Sm9obiBTLg==?= | last post by:
I developed a Windows Service application written in vb.net and have successfully installed it on many workstations (over 25 PCs). All workstations have Windows XP SP2 installed. There are two...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
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,...
0
7432
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...
0
7517
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...
0
5676
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,...
0
4743
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.