-4

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.

Saman Parser
  • 148
  • 14

2 Answers2

5

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.

Community
  • 1
  • 1
Cody Gray - on strike
  • 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
  • 1
    By 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
2

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.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • 1
    Not 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