Solved

c#: spawn a process from a service

Posted on 2009-05-05
5
851 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 74

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

23 Experts available now in Live!

Get 1:1 Help Now