Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

c#: spawn a process from a service

Posted on 2009-05-05
5
Medium Priority
?
882 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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