Solved

c#: spawn a process from a service

Posted on 2009-05-05
5
853 Views
Last Modified: 2013-12-17
can someone show me a piece of code that works in c# - spawning a process (createprocess / process api) from a service ?

I dont need to run GUI applications or anything that demands a user to be logged on to the system, i just need to be able to run small worker jobs (exe / cmd files).

its not a problem outside the service, but inside it seems to be difficult and there are tonnes of examples on the net and discussions about it, those ive tried hasnt worked yet.

So would be thankful if you could post a code that works - thanks
0
Comment
Question by:thordk
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
tculler earned 500 total points
ID: 24308315
I'm not sure whaty ou mean by "from a service". If you need to create and keep track of a process, the Process object in the System.Diagnostics namespace is more than ideal. If you just need to start a process, calling static method Start of Process will suffice, also allowing you to supply optional command-line arguments in the method call. For example:

System.Diagnostics.Process iexplore = 

     new System.Diagnostics.Process("iexplore.exe",

"http://www.experts-exchange.com");

iexplore.Start();

// Do whatever you need to do

iexplore.Kill();

// Ends the process immediately.
 

// OR
 

System.Diagnostics.Process.Start("iexplore.exe",

"http://www.experts-exchange.com");

Open in new window

0
 

Author Comment

by:thordk
ID: 24308330
By service i mean - a "Windows Service" - you know, an application running in the background.
0
 

Author Comment

by:thordk
ID: 24308657
that doesnt seem to work no. There is a difference running from a windows-service than an ordinary application.

btw should be able to run on XP & Vista ->
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24309357
The code that tculler posted is the method of starting a process (and yes it will work inside of a service). The issue you are most likely having is that you are expecting to see the process running (e.g. a command window). This will not happen because services run in their own space and do not have a visible desktop.
0
 

Author Comment

by:thordk
ID: 24309748
yes sorry its working fine, was abit fast there as i thought it was similar to another example. But thats working just good. thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now