Solved

c#: spawn a process from a service

Posted on 2009-05-05
5
865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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