0

Not sure if this is more suited to SO or Server Fault.

During unittesting ran across what appears to be a limitation of "Fast User Switching" on windows 10. Had the following two line batch file.

C:\Windows\System32\timeout.exe 30
C:\Windows\System32\shutdown.exe /L

Open a CMD.exe and run the bat file. 'Fast Switch' (ie logon) to another account. The timeout completes as scheduled, but the logoff statement has no effect...user is still logged on. When you return, you can see the shutdown.exe is on the screen, but the session is still active.

If you run the script and stay logged in to the account, after 30-seconds, the logoff command works as expected.

Also discovered the same limitation if instead of fast-switching, you invoke the screensaver (ie: Lock the account). After 30-seconds, the first command finishes but the session is still active.

I've scoured MSDN and Google, but there is scant documentation on Fast-user switching and the Lock functionality and how they might limit what a user can do while switched or locked.

user590028
  • 11,364
  • 3
  • 40
  • 57

1 Answers1

0

You can definitely end a session while it is locked, but you can't do it with the normal ExitWindows API call that shutdown.exe is using. See the notes in MSDN:

EWX_LOGOFF
Shuts down all processes running in the logon session of the process that called the ExitWindowsEx function. Then it logs the user off.

This flag can be used only by processes running in an interactive user's logon session.

For a solution using only batch files, logoff and related terminal server tools allow you to end the locked session. Example using PowerShell which works when tested on Windows 10 1903:

sleep 30    
logoff ([System.Diagnostics.Process]::GetCurrentProcess().SessionId)

As for documentation, multi-session support of windows is documented most strongly for Remote Desktop Services. All of the advice and API's used for RDS apply for Fast User Switching. See About Remote Desktop Services.

Mitch
  • 21,223
  • 6
  • 63
  • 86