2

I want to do (programmatically, using WinAPI) exactly the same what Windows does when you click on 'Switch User' in the Start Menu. Namely, to show the screen where all available user accounts are listed and you can switch to another account still being logged on as the previous one. As far as I know it's called 'fast user switching'. I have no credentials, my task is to let users of my app switch to another account using their own credentials.

Also, is there a way to know, if the option is enabled in the Start menu? Because if it is not, I don't want to show the option in my app as well.

UPDATE

I have used ::ExitWindowsEx() for logging off, but there is no EWX_ flag for switching.

Regards,

noober
  • 4,819
  • 12
  • 49
  • 85
  • 1
    Why can't the users just do this themselves? Why would another app need to provide more UI when the existing UI works perfectly well? – David Heffernan Nov 26 '15 at 13:08
  • 1
    @DavidHeffernan The answer is simple: an alternative launcher adapted to special hardware/use cases. – noober Nov 26 '15 at 13:09
  • 1
    If you are seeking to replace the default Windows screen, you can write a custom GINA module https://msdn.microsoft.com/en-us/library/windows/desktop/aa380543(v=vs.85).aspx. Otherwise, it appears that launching the Windows default Fast User Switching screen takes calling the undocumented `ShellStartCredentialServer` function on the default Microsoft GINA, as per http://www.remkoweijnen.nl/blog/2008/11/26/executing-a-fast-user-switch-programmatically-part-1/. Needless to say, calling undocumented APIs is a bad idea. Ah, and there is no GINA since Vista. – PeterK Nov 26 '15 at 13:55
  • @PeterK Thank you, `ShellStartCredentialServer` seems to be what I'm looking for. Have to check it at first. – noober Nov 26 '15 at 15:01
  • Er, GINA? That's been dead for 10 years. – David Heffernan Nov 26 '15 at 16:28

1 Answers1

3

It sounds like you want the WTSDisconnectSession() function:

Disconnects the logged-on user from the specified Remote Desktop Services session without closing the session. If the user subsequently logs on to the same Remote Desktop Session Host (RD Session Host) server, the user is reconnected to the same session.

You use it like this:

WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, FALSE);
Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
  • Works perfectly. Thank you. – noober Nov 27 '15 at 08:54
  • BTW, it's not working on several virtual machines running under Oracle VirtualBox. If you test the solution on virtual machines, keep in mind it's not a real issue. – noober Dec 08 '15 at 07:39