Shortcut to Switch User in Windows Vista

At home, our PC running Vista is rarely rebooted and is either in a low power state sleeping or being used by either me or my wife. One thing we’ve taken great advantage since the XP days is Fast User Switching which allows someone else to log in to their desktop whilst yours is kept running in the background. My wife and I had got quite used to doing a quick WinKey+L (as you do) before relinquishing control of the PC to one another. In Windows XP WinKey+L is does a “lock workstation” which in non-domain machines takes you back to the Windows logon screen. Unfortunately on Vista it takes you to a “workstation locked” screen, so you then have another mouse click on the Switch User button (followed by monitor re-syncing itself – why does it do this? All users run at the same screen resolution) to take you to the users screen. Of course there is a “Switch User” command tucked away in the little menu next to the lock button on the start menu – but a quick keystroke is what we’re after here.

So – I go off searching for a shortcut key that does a “switch user” rather than “lock workstation”. After a 20 minutes fruitless Googling for some special key combination, I sat back, thought about it logically and came up with this solution:

  1. Create a shortcut on your desktop to TSDISCON (* see below) and call it something like “Switch User”
  2. Go the shortcut Properties page and assign a shortcut key. Note that unfortunately you can’t use the Windows Key in your shortcut – so I went for CTRL + ALT + SHIFT + L
  3. Right click Start button and choose “Open All Users” and move the shortcut into the Programs folder (confirming the UAC prompt as you go).
  4. Log out, and back in again. This is necessary because Explorer hasn’t noticed there’s now a shortcut with a new shortcut key it should be taking notice of.

And that did it. CTRL + ALT + SHIFT + L isn’t quite a neat as WinKey+L but it’s a hell of a lot better than poking around in the Start Menu.

* What is TSDISCON you ask? It’s the Terminal Services Disconnect command. Fast User Switching is all made possible by the core Terminal Services technologies which introduced the concept of multiple Window Stations or “sessions” running concurrently on the one machine. It was of course originally designed to support multiple users connecting concurrently to these sessions over the network using the Remote Desktop Protocol (RDP), but Windows XP took advantage of the multi-session architecture to enable Fast User Switching. (The RDP stuff is still there but hobbled to only allow one user to connect at a a time.)

UPDATE: If you don’t have tsdiscon.exe on your system for some reason (maybe it’s only available in Business/Ultimate or something) then you can use the following C# code (compiled into a Windows EXE using C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe if you don’t have Visual Studio) to do the same thing. Tsdiscon.exe is just a wrapper around WTSDisconnectSession. I used Dependency Walker (aka depends.exe) to find out what was being used:

UPDATE 2: For your convenience: I’ve compiled the below and packaged it into a ZIP along with the source for download here.

using System;
using System.Runtime.InteropServices;
using System.ComponentModel;

class Program
{
  [DllImport("wtsapi32.dll", SetLastError = true)]
  static extern bool WTSDisconnectSession(IntPtr hServer, int sessionId, bool bWait);

  const int WTS_CURRENT_SESSION = -1;
  static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;

  static void Main(string[] args)
  {
    if (!WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE,
         WTS_CURRENT_SESSION, false))
      throw new Win32Exception();
  }
}
About these ads

66 Responses to Shortcut to Switch User in Windows Vista

  1. Mike says:

    Simple solution but works perfectly and the bonus is that you can use whatever key combination you want (within reason) rather than the one imposed by MS. Many thanks for this. Shame that for user switching Vista turns out to be a step backwards from XP.

  2. dl says:

    what if there is no tsdiscon.exe file present? I suppose I could add it by downloading it, or activating certain windows services, but it should not be necessary.

    Where does the shortcut in the start menu point to? It works, so I should just be able copy that path or shortcut.

  3. Duncan Smart says:

    @dl, On my system it’s C:\Windows\System32\tsdiscon.exe

  4. Garrett says:

    Does anyone who has a 32-bit version of Vista have this tsdiscon.exe file? I’ve got the file (found online) but when I run it it says that I may need Vista 64-bit.

  5. duncansmart says:

    @Garrett – I’ve updated the post and added some code that you can compile into an EXE that will do the same thing as tsdiscon.

  6. Garrett says:

    Duncan,

    Do I have to be logged into a server for the code to work? I’ve got Visual Basic Studio and had already found the Basic version of the code, but when I ran it nothing would happen (the WTSDisconnectSession call would run and return no error code but nothing would happen). That’s why I was looking for the tsdiscon program itself. Do you think the C# code would work differently?

    Thanks! :)

  7. Brian Lang says:

    tsdiscon.exe may only come with Windows Vista SP1.
    Then, while the cursor was in the Shortcut Key field, I pressed the Windows Key and S (Short for Switch User) and Vista filled in Ctrl + Alt + S. I’m going to try it now.

  8. Brian Lang says:

    Ok, found a gotcha in the process. I had done an upgrade from Windows XP, and the copy of tsdiscon.exe I found was the one in the Windows.Old folder. It wouldn’t work in Vista. I corrected the shortcut and I was in business.

    I also decided to use a different shortcut (same as yours) as Ctrl + Alt + S seemed too close to the Save As… item in most software.

  9. Pingback: BrianLang.ca » links for 2008-07-25

  10. b says:

    Hey, thanks for the tip! Compiled it using csc.exe as I didn’t have TSDISCON.EXE on my system (Win Vista Home Premium SP1), and it works perfectly.

    Now when I am done using the laptop I use the shortcut key to the shortcut on my desktop, and my wife can easily login to the laptop later on, without having to click “switch user.” Thanks!

  11. Matt says:

    Great tip. I was able to use create a shortcut to the file and map the “logoff” button on my keyboard to that shortcut. Now, instead of either logging off or locking, it just drops us back to the switch user screen!

    Thanks for figuring it out!

  12. Rommelaar says:

    I agree, great solution. Thanx!

  13. BigFurryMonster says:

    Does anyone have the file tsdiscon.exe available for download?

    I tried using the compiler mentioned above but it does nothing when I start it.

  14. Cyooties says:

    To use the compiler method mentioned above first copy and paste the C# code into notepad. Save it as a .txt file (I named it switchuser.txt) on your desktop. Then navigate to the folder containing csc.exe as indicated above. Now take your switchuser.txt file and drag and drop it onto the csc.exe file. It will out put a .exe file onto your desktop (switchuser.exe). Presto, you’re done. Double clicking on the file will take you to the switch user screen. You may want to change the icon though as it just uses the default system icon.

  15. Duncan Smart says:

    @Garrett, @Cyooties, @BigFurryMonster: I’ve updated the post to include a download link to ready-to-run EXE.

    • Steve says:

      I thought you would like to know, I downloaded your switchuser.zip for a friend still using vista onto my win7 machine. I ran the exe on this win7 machine and it works for this version of windoze too.

  16. subkron says:

    Used the zipped exe since I have home premium (no tsdiscon). Ended up pinning the shortcut to the Start Menu, moved it to the top of the list.
    Piece of cake.

  17. Marcrosoft says:

    Bravo! 30 clicks 15 hits on google and yahoy and all we needed was this. Great Job!

  18. Farshied says:

    Dude, You are awesome, I owe you a shirt, check out my web site and send me an e-mail.

  19. DiscoStu says:

    Thank you so much – a great work-around!

  20. Mike Jones says:

    Superb! Great solution.

    (Running Vista Home Premium).

  21. random says:

    Thank you thank you thank you! it works perfect

  22. Velizar says:

    Thank you very much – it works fine for me too. I was looking for this for some time.

    I even succeeded to improve a bit your solution ;-)
    After making a shortcut on the desktop I decided to put it in my Quick Launch bar (as most my shortcuts). Then I decided to try again what do different Windows+ shortcuts.
    I was surprised to see that Win+2 Switches User in the same way as my new shortcut does.
    Finally I understood that Win+ starts a shortcut from Quick Launch Bar.
    For example if “Switch User” shortcut is third shorcut in the bar – then Windows+3 key sequence will execute it.
    So – there is a way for simpler shortcut key with “Windows” key.

    Best regards

  23. TheSpiderman says:

    Wow !!!!

    Finally, after hundred sites telling me to add a shortcut with tsdiscon.exe which I don’t have on my Vista version.

    This is awsome and million thanks for this share Duncan !!!

    Spidey

  24. Dr. Memory says:

    So totally sweet. Works like a dream in Vista HP. You are the man!

  25. Ty says:

    I was wondering the following. I only have two users of my computer. Is it possible to modify your great tool to simply toggle between the two which would save the step of selecting the next user. Thanks in advance.

    • Duncan Smart says:

      I had the same idea, and I think it should be possible. It would involve
      running some elevated code (perhaps using Task Scheduler).

      • Steve says:

        Hi Duncan,
        I was wondering if you have tackled this variation – “Toggle User” yet. I, too, have just two users and would find this VERY helpful. I have disabled UAC so I assume that the need for “elevation” wouldn’t be necessary???

  26. Krishna says:

    Hi, Thank you so much for Duncan , Cyooties , Velizar.

    Perfect solution combination. I was looking for this answer from a week and finally I am very happy now. Thank you so much.

    You people are teally great and helping everyone. Thank you once again.

  27. Palmito says:

    Hi,

    Thanks I have been looking for this for a long time :-)

    As Vista adds in all of the Win+ keys to launch the shortcuts in the Quick Launch menu I would suggest you move your shortcut to Quick Launch as first shortcut and therefore allowing to swith using WinKey+1

    Cheers,
    Bigup urself

  28. SmashOgre says:

    Thanx man. Your awesome. I will get a lot of use out of this code!! Much appreciation for your effort of putting this out there for us.

  29. Pingback: DancingSamurai.ca | Windows Vista – Switch User Shortcut

  30. Stupidfunny says:

    OMG, thank you soooo much, spent half an hour already trying to find a command or api that does this!

  31. Jules says:

    Interesting. In XP with multiple displays, running tsdiscon.exe causes all my windows to move to the primary display and resizes maximized windows to 1024×768. I take it it doesn’t do this on Vista?

  32. Brian says:

    Thanks for the information, I have a Microsoft wireless keyboard and was trying to figure out a way to change users quickly. SInce it has the 5 program keys when I pressed key 1 it asked for a command to use. I just typed TSDISCON no path, no exe and saved it. hit #1 and the change users screen came right up.

  33. cebiggs says:

    Brilliant. Thank you, Duncan.
    Amazing how those 3 mouseclicks got extremely tiresome.
    I wonder if I should do away with those painful passwords now for even easier switching?

  34. Ivan says:

    Thx very much!

  35. Scorpiono says:

    Thanks, you made my day! ;)
    Happy December!

  36. kenora_guy says:

    WOW!!! Works like a charm.

    Duncan, you know I’ll be adding your blog to my fav’s.

    ThanX a bunch!

  37. JP says:

    thanks for the downloadable package, much appreciated as I don’t have the TSDISCON on my machine (vista home)

  38. Anthony says:

    This is great, and exactly what I was looking for. The code is nice too, not having to download strange files is nice.

    However, it gets me wanting more: is it possible to add a step after the disconnect to specify the next account to login with? Our home PC is shared just like yours between the wife and I (with a separate admin account), so it would be neat to save another click and just login straight to the opposite account. I guess it would mean adding an argument to the executable.

    • Duncan Smart says:

      Possible, but it would ge complicated: 1) it would require elevation, and 2) the accounts would need to have passwords (there’s a Windows policy that requires such logins to have passwords)

  39. Michael Allen says:

    Hi, Duncan: Thank you for your elegant solution. I put in first position on the launch bar so now its as handy as Alt+Tab! And many thanks also for the specific CSC.exe compiling instructions.

    You might be interested to know that this works on Windows 7, too. I am using Home Premium 6.1.7600.

    All the best from Florida, USA

  40. jerry says:

    works in windows 7 starter! but when I log into another account it warns that the (currently logged in) account will be logged off first. Any way to fix?

    • Duncan Smart says:

      Sorry, I don’t have a copy of Starter with which to investigate/test.

  41. Luke says:

    Hi Duncan

    Just downloaded your Zip for Vista Home – works like a dream. Thanks so much for this.

    Luke

  42. Absynth says:

    Thanks – that’s all right! =)

  43. Pingback: Drija » Archive » How do I skip the Switch User screen in Vista?

  44. Flupi says:

    I agree, great solution. Thanx so much for this!

  45. Jane says:

    Cool shortcuts, very useful. Thanks a bunch!!! I found a few move shortcuts here: http://www.usingcomputers.co.uk/tutorials/useful-windows-shortcuts.php its worth taking a look at combined with this article. Thanks, keep up the good posts!

    Patrick

  46. Duncan, we had the same train of thought.

    You can also make the process automatic with Task Scheduler. I wrote up how at http://blog.throbs.net/2011/02/11/VistaWin7+Solution+Skip+The+Switch+User+Screen.aspx

  47. Pingback: HOWTO: Create A Shortcut To Switch Users In Windows XP/Vista/7 « The Brainwrecked Tech

  48. Jesus says:

    Hi Duncan.

    I’m using Vista Starter and when log into another account it warns that the (currently logged in) account will be logged off first. Any way to fix? Thank you

  49. Pingback: How do I skip the Switch User screen in Vista?

  50. edward says:

    Great post thanks a ton!

  51. marius says:

    Merci cela fonctionne parfaitement même avec plusieurs années de décalage!!! ( par rapport au premier post!!)

  52. Susan says:

    I have win7 and discovered the use of tsdiscon a couple of days ago. It works great but, playing two copies of a game, I really need a faster switch. Sometimes it is only 2-3 seconds, other times it is more like 10, plus the time to enter the password. There are a couple of posts that allude to “elevation” (not sure what the term means) but is there no way that userid/password can be passed to enable doing away with the switch user screen?

  53. joggl@brainity.com says:

    Hi there!

    I also have two users using one pc, so swiching is a standard task. Both users are password protected, but they trust each other, so there is no reason why one user should not be able to log into the other account.
    Therefor I wanted to have a shortcut for switching from A to B (say CTRL-SHIFT-B) and another one to switch from B to A (e.g. CTRL-SHIFT-A)

    This is how I did it:

    * install SuRun (sf.net)

    * create two files (e.g. switch_AtoB.bat and switch_BtoA.bat) containing:

    **************************************************************************************************
    @echo off

    rem *** set this: ***

    set tsuser=USER
    set tspwd=PASSWD

    rem *** do not change this: ***

    set myVar=””
    FOR /F “tokens=1 delims=” %%A in (‘query user ^| findstr %tsuser%’) do SET myVar=%%A echo %myVar%
    set id=%myVar:~43,1%
    rem echo %id%
    C:\Windows\SuRun.exe %windir%\System32\tscon.exe %id% /password:%tspwd%
    **************************************************************************************************

    * set user and pwd (the one you are swiching to…)

    * create a shortcut to this file on the desktop or start menu and give it an icon and keyboard shortcut

    * use shortcut and tell SuRun to remember higher privileges

    Thats about it.

    I know, its not nice to save the passwords clear text but that’s all i’ve got. using Win-L still locks your screen preventing others to simply read the batch file.

    UAC does not have to be disabled. Using SuRun I don’t think the user has to be Administrator privileged.

    P.S. the other user has to be logged once after startup in order to make this work
    P.P.S. I just wrote this and it works but with very little testing right now…
    P.P.P.S. i use this on win7 prof

    • Duncan Smart says:

      Nice one! I’ve toyed with doing something like this in the past, looks like you’ve come up with a good solution.

      • joggl says:

        thanks, hope it works for others as well!

        one more thing: i’m using a german version of win7

        so this is the output of ‘query session’ is this:

        C:\Users\joggl>query session
        SITZUNGSNAME BENUTZERNAME ID STATUS TYP GERÄT
        services 0 Getr.
        >console joggl 1 Aktiv
        Anna 2 Getr.

        I would think, another language version of windows could place the ID somewhere else on the screen (some chars more left or right). In this case you would have to change ’43’ to the appropriate value (position of number from left border – 1) here:

        set id=%myVar:~43,1%

        If you expect more than 10 user sessions you should change this to e.g.

        set id=%myVar:~42,2%

        If a user owns more than one session it should take the first in the list.

        There is no exception if the other user is not logged in. So there will be an error message. Maybe I’ll fix this later on.

        cheers,
        joggl

Follow

Get every new post delivered to your Inbox.

Join 36 other followers

%d bloggers like this: