How can I load a 'login form' in OnStart event of windows Service?! I know windows service is incompatible with UI. but I need to do this without using windows startup.. Is it possible? and how? Thanks a lot.
-
2_Is it possible?_ Did you tried it ? – Soner Gönül Apr 05 '13 at 06:46
-
I don't know. I'm searching to find a way.. – Saman Parser Apr 05 '13 at 06:49
-
asking directly on stackoverflow, is this your way of search? – Freelancer Apr 05 '13 at 06:50
-
1So you know that a Windows Service should not do anything with the UI yet you ask it anyway? – ZippyV Apr 05 '13 at 06:51
-
1Your design is probably wrong. – L-Four Apr 05 '13 at 06:52
-
definitely.. It's one way. and I experimented other ways during last week.. – Saman Parser Apr 05 '13 at 06:53
-
Yes.. but I'm searching for other designs.. – Saman Parser Apr 05 '13 at 06:54
-
The question doesn't ask for other designs, though. It claims that something is impossible, then asks how to do it anyway. – Cody Gray - on strike Apr 05 '13 at 06:55
-
Do you really want us to help you with the information you have provided? It's not possible, be more specific. – L-Four Apr 05 '13 at 06:55
-
Also read: http://stackoverflow.com/questions/53232/how-can-i-run-a-windows-gui-application-on-as-a-service – L-Four Apr 05 '13 at 07:17
-
See also ["Can a Windows Service have a GUI? Should a Windows Service have a GUI?"](http://www.coretechnologies.com/WindowsServices/FAQ.html#GUIServices)... – CoreTech Apr 05 '13 at 13:17
2 Answers
How can I load a 'login form' in OnStart event of windows Service?
You cannot do this, because Windows services cannot display a user interface.
I know windows service is incompatible with UI.
Oh. You already knew that. Good.
but I need to do this without using windows startup..
This does not change the fact that it is not supported and will not work.
Is it possible? and how?
No, because:
windows service is incompatible with UI.
So what do I do!?!
The real answer here is that your design is wrong.
If you need someone to log in to your application, you should not be creating a service.
Just make a standard Windows application (e.g., using Windows Forms or WPF) and set it to start automatically when any user logs on to the computer. This can be accomplished easily by adding a shortcut to it to the All Users "Startup" folder.
Then, when your app runs, you can display whatever UI you need to, without the limitations of a service.

- 1
- 1

- 239,200
- 50
- 490
- 574
-
"Windows services cannot display a user interface" - they can. Yes, they shouldn't, and it isn't easy, but... – Dennis Apr 05 '13 at 06:58
-
1By design, services do not display a user interface. I'm not sure if you're talking about a security vulnerability that existed in Windows XP and older versions, or if you're referring to some new type of Session 0 exploit, but I don't think either of those things negate the statement I made. You can also take a magic marker and draw the form onto the monitor. This doesn't count either. – Cody Gray - on strike Apr 05 '13 at 07:00
-
It is not possible. Not only does it not make any logical sense, steps have explicitly been taken in the design of the operating system to prevent it from ever happening. I already suggested another way. – Cody Gray - on strike Apr 05 '13 at 07:04
-
I think you are only reading part of the comments. You should not do it. NOT. A windows service is unattended. Change your design. – L-Four Apr 05 '13 at 07:04
-
I told u I'm not going to use startup folder. because user can change it after login.. I need something like Windows-Login-Form.. – Saman Parser Apr 05 '13 at 07:08
-
A standard user won't the requisite permissions to modify the "All Users" folders. The only thing they can control are their personal folders, that's why you don't put it there. And if they're an administrator, all bets are always off, since they have control over services, too. – Cody Gray - on strike Apr 05 '13 at 07:09
-
But u have control on services.. u can change a 'windows service' which nobody can stop it. even administrator – Saman Parser Apr 05 '13 at 07:12
If you need to combine UI interaction with a service, you ought to write two programs - the service, which exposes some kind of API, and a client program that interacts with that API (using whatever IPC mechanism you want to choose)
Just remember that multiple users can log onto the same machine, so you ought to write everything to cope with multiple instances of the client program running at the same time.

- 234,701
- 27
- 340
- 448
-
1Not only do you have to deal with multiple users being logged on to the machine, you also have to deal with the case of *no* users having logged on to the machine. Where's it going to display the logon form if no one has logged in yet? – Cody Gray - on strike Apr 05 '13 at 06:56