Run application on Win7 logon screen

2.4k Views Asked by At

I'd like to run an application on the logon screen of Windows 7 from a service.

I've been doing long researches on this and trying out different ways already, but unfortunately wasn't fully successful so far. I managed to run the application on the lock screen of a currently logged on user - which at first looked to me as it was what I basically tried to achieve. However, I then realized that there are different logon screens for every user and a general one (user independent).

My guess is that this user independent logon screen (that comes up directly after booting when multiple accounts are available or when clicking "switch user" on the lock screen) runs in session 0, while user 1 runs in session 1, user 2 in session 2 and so on. The problem is that if I run an application in session 0 (with "winsta0\winlogon") it's not visible; running in session 1 works fine but doesn't help much as a user has to be already logged in for that.

So how to run an application on the user independent logon/welcome screen? What are the correct parameters and functions for this purpose? Does anybody have a working example for demonstration? (Delphi is preferred but actually any other language will do as well!)

1

There are 1 best solutions below

3
On

The only supported way to do this is to implement a credential provider, as per RRUZ's comment.

If you don't mind breaking the rules, a service running as local system should be able to launch a subprocess in the session of your choice. Use OpenProcessToken to get a handle to your security token, duplicate it with DuplicateTokenEx, use SetTokenInformation to change the token session identifier, then call CreateProcessAsUser to launch the subprocess. (Initially, it would be simplest to use a separate executable, but once you've ironed out the bugs you could roll the service and the subprocess into a single executable, for example by using a command-line argument or an environment variable to distinguish the two cases.)

The WTSGetActiveConsoleSessionId function will tell you which session is currently connected to the physical console.