Automatically logon user when another user logs out using PowerShell

3.1k views Asked by At

I am building a Windows embedded kiosk application that automatically logs in a default user on boot and launches the kiosk application. Once this occurs, the user cannot interact with any windows features, only the kiosk application.

However, when an admin comes to work on the system, he can log out of the default windows user account and log into a windows admin account. When the admin manually logs out, I want to automatically log the default user back in, and launch the kiosk application.

I have been searching for a couple hours on how to accomplish this with no luck. I am thinking a Powershell logoff script or something similar, but have no idea how to implement it (I have not Powershell experience). Does anyone have an idea on how to accomplish this?

Note: I already know how to automatically log in the default user and launch the kiosk app on computer startup (using group policy editor). I am only asking how to do the same thing when the admin logs off.

2

There are 2 answers

1
philselmer On BEST ANSWER

Create a logoff script with the following registry keys. Doesn't have to be powershell, this code would work for a normal command line batch script. The username is "user" and the password is "user"

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUsername /t REG_SZ /d user /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d user /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v ForceAutoLogon /t REG_SZ /d 1 /f

If you have a "welcome message", you will still have to click OK to fully log in, though

Here is how you create a logoff script: http://technet.microsoft.com/en-us/magazine/dd630947.aspx

1
vincent strobbe On

You can put a PS script in the Local group policy editor (logoff script). You have to

  1. Make a script that checks which user is logged in.
  2. And if it is the admin you can use the shutdown -s so it will restart the PC and auto login the user.

Then it's what you want, only an unnecessary reboot.

Be careful: if your script is wrong about the usercheck (= admin), you cannot log off the user and you can't go anymore to the admin anymore!