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:
- Create a shortcut on your desktop to TSDISCON (* see below) and call it something like “Switch User”
- 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
- Right click Start button and choose “Open All Users” and move the shortcut into the Programs folder (confirming the UAC prompt as you go).
- 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:
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();
}
}
UPDATE 2: For your convenience: I’ve compiled the above and packaged it into a ZIP along with the source for download here.
16 Comments so far
Leave a reply
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.
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.
@dl, On my system it’s C:\Windows\System32\tsdiscon.exe
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.
@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.
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! :)
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.
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.
[...] Shortcut to Switch User in Windows Vista (tags: vista tips) [...]
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!
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!
I agree, great solution. Thanx!
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.
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.
@Garrett, @Cyooties, @BigFurryMonster: I’ve updated the post to include a download link to ready-to-run EXE.
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.