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!

windows service

Status
Not open for further replies.

kokon

Programmer
Apr 27, 2006
31
0
0
PL
Hello! I have a problem with starting notepad.exe from windows service. It starts but i cant see any window. I can only see that it starts from windows task manager.
Thx for help. My source is:
-----------------------------
protected override void OnStart(string[] args)
{
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.Start();
}
 
This is a common mistake.

You should not be launching GUI Apps from a Service. This is because a service starts before a user is logged in. So when the GUI App is launched it is run as the System user and not the logged in user.

You should try running a small app that runs at startup (login) that will launch GUI for you.

It is possible to launch a process as a different user but it is probably not the best idea.
 
Ok, so is it possible if my service will start gui application before login without visible gui and then after user login the gui will become visible?
 
No. You cannot change who is running a process after it is running. By default, before a user is logged in the process will run as System and not be visible. After the user logs in you would have to launch the app in order for it to be visible.
 
May I launch it and put an icon in system tray, and when i would click this icon, GUI will apeared??
 
I would create a simple Windows Application which has no forms but has a SystemTray icon (notification icon) and put a shortcut to it in the "startup" folder so it runs when the user logs in.
 
I agree with everything that JurkMonkey has said. Windows Services are intended for unattended programs -- stuff like database servers and network communication processes, which don't require any interaction with the user.

If you want something run every time a user logs in, put it in the startup group -- it's what it's there for.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top