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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launcing exe from windows service

Status
Not open for further replies.

Panopticon

Programmer
Mar 29, 2006
2
CA
Hey folks,

I'm trying to open notepad from a windows service. The service runs as a user with sufficiant privledges and it actually launces a notepad.exe process, however notepad and anyother exe for that matter doesn't appear to initilize. It just sits in the process explorer. From what I can find, .net2 makes things easier, and I could also use an un-managed API.

Is this a bug with windows? or is there a proper way to create a process within a service? I've also tried using the runas commnad however this needs to be all automated and it doesn't seem like there is any easy way to send it a password when it prompts.

code:
Code:
Process myProc = new Process();
string path = "c:\\winnt\\notepad.exe";
OnStart()
{
    myProc.StartInfo.FileName=path;
    myProc.Start();
}

thread732-1026106
 
you have to use the command line "runas" command to launch the gui as the current user. In your Arguments, you will also have to specify the user's password.

Also: when you use runas, you have to specify the local domain if you're on any kind of network.
 
Services generally aren't intended to interact with the desktop.

What happens if the machine is booted, but no one logs in? Who will be there to interact with your copy of Notepad, especially since the desktop hasn't been constructed, and the *CurrentUser registry keys haven't been built?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Go into your services manager and view the properties for the service. Under the 'Log on' tab, you can set the service to be allowed to 'interact with the desktop'.

Jeff W.
MCSE, CNE
 
Yup, that did the trick! I dont' neccessarily need to open notepad but I wanted to see if its possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top