Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start a Process from a Windows Service

Status
Not open for further replies.

123qweasdzc

Programmer
Sep 27, 2005
20
PT
Hello :).

I want to start a process from a Windows Service. To do that I have the following code:

private System.Timers.Timer timer;
private Process process;
private bool isProcessRunning = false;

protected override void OnStart(string[] args)
{
timer = new System.Timers.Timer();
timer.Interval = 5000;
timer.AutoReset = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(startProcess);
timer.Start();
}

private void startProcess(object sender, System.Timers.ElapsedEventArgs e)
{
if(!isProcessRunning)
{
EventLog.WriteEntry("Process will start...");
isProcessRunning = true;
process = new Process();
process.StartInfo.FileName = @"C:\Program Files\AllMyMovies\allmymovies.exe";
process.Start();
}
}

I cannot understant why the process do not start because the entry "Process will start" is written in the event viewer log. Can someone say what's wrong? I hope so :).

Thanks in advance,

Ricardo
 
Problem solved. The problem is that running a process from a windows service, it will not launch an user interface. All the processes run in backround.

For me there is no problem because the real process I want to start do not have a user interface.
 
you can check to see if you are able to launch an app with an interface by checking the state of this boolean:

System.Windows.Forms.SystemInformation.UserInteractive

Its saved me aon a few occasions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top