Windows Service: Running Script Or Executable From

A

Amy L.

I have a windows service where I would like to launch a script (bat, cmd,
vbs, exe, etc) from the service. This script should execute in the
background and not require any input from the user (i.e. not interact with
the desktop).

I have been looking at System.Diagnostics.Process.Start() to launch this
script.

Here are my questions based on this.
1.) Is this the right namespace to be using?
2.) I want the program to wait until the script finishes processing is this
possible?
3.) Is there anything else I should consider?

Thanks
Amy.
 
J

Jonel Rienton

Amy said:
I have a windows service where I would like to launch a script (bat, cmd,
vbs, exe, etc) from the service. This script should execute in the
background and not require any input from the user (i.e. not interact with
the desktop).

I have been looking at System.Diagnostics.Process.Start() to launch this
script.

Here are my questions based on this.
1.) Is this the right namespace to be using?

I would use System.Threading namespace or use delegates[1]
2.) I want the program to wait until the script finishes processing is this
possible?

This is the reason why i suggested delegates in #1 question, with
delegates, you can use callback function to grab whatever data you would
need from the asynchronous/synchronous call
3.) Is there anything else I should consider?

I would be concern with security on what you're trying to accomplish and
since i'm not exactly sure what task the script will do, i cannot
comment any further.
Thanks
Amy.

[1] look up asynchronous/synchronous programming in MSDN library


hth,
Jonel
 
G

Guest

You could use System.Diagnostic.Process for the next reasons
1. It's better for performance then Threading
2. You can use delegates - Process has event Exit, so enjoy
3. Method Start of Process class is static and return process - so you could to connect to his events without writing a lot of code.
 
M

Mark

Amy said:
I have a windows service where I would like to launch a script (bat,
cmd, vbs, exe, etc) from the service. This script should execute in
the background and not require any input from the user (i.e. not
interact with the desktop).

I have been looking at System.Diagnostics.Process.Start() to launch
this script.

Here are my questions based on this.
1.) Is this the right namespace to be using?

I would use System.Threading namespace or use delegates[1]

System.Threading won't run scripts (or other .exes) and neither will delegates, so,
yes, you are looking in the right place.
This is the reason why i suggested delegates in #1 question, with
delegates, you can use callback function to grab whatever data you
would need from the asynchronous/synchronous call

Yes, you do a Process p = Process.Start("exename", "args"); and then p.WaitForExit();
Scripts don't do callbacks.
I would be concern with security on what you're trying to accomplish
and since i'm not exactly sure what task the script will do, i cannot
comment any further.

Remember that the script will run as the user that the service is logged in as. By
default that is the LocalSystem account, which is fairly privelidged on the local
system.
Thanks
Amy.

[1] look up asynchronous/synchronous programming in MSDN library


hth,
Jonel

Mark
 

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