Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Saves the last login so the last user account on the login screen (if enabled) is preserved after you remote login
- # to a computer using a different account. Run script before remote logging into a computer and make sure it's
- # started before you log in. It will wait for you to login before it completes.
- # It will save the current value of last logged in user so after you log in, it will change it back to what it was.
- # Save current last login info BEFORE logging in as a different account. Make sure max script login time is high
- # enough so you have time to complete the login.
- $SID = (Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI").LastLoggedOnUserSID
- $displayName = (Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI").LastLoggedOnDisplayName
- $user = (Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI").LastLoggedOnUser
- $SAMuser = (Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI").LastLoggedOnSAMUser
- # Wait for admin to get logged in. Soon as the last logged in keys change, reset them back to what they were.
- while ($user -eq ((Get-ItemProperty "HKLM:\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI").LastLoggedOnUser)) {
- start-sleep 5
- }
- reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI /v LastLoggedOnUserSID /d $SID /f > $null
- reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI /v LastLoggedOnDisplayName /d $displayName /f > $null
- reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI /v LastLoggedOnUser /d $user /f > $null
- reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI /v LastLoggedOnSAMUser /d $SAMuser /f > $null
- echo "Last login reset to $user - $displayName"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement