Created
November 4, 2014 15:55
-
-
Save jonman364/f1fc3408eb0c1c734932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' resetlogon.vbs | |
' Jon Dunlap 8/3/2010 | |
' | |
' Reset last logon user ID in Windows XP or Windows 7. In Windows 7, script | |
' automatically elevates itself to write to the registry. | |
' | |
' 5.1 WinXP; 5.2 Win2003; 6.1 Win7 | |
Option Explicit | |
const HKLM = &h80000002 | |
Dim objWShell, objAShell | |
Dim osVer, strKey, strVal, strValVal | |
Dim canWrite | |
Set objWShell = CreateObject("WScript.Shell") | |
osVer = objWShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion") | |
If osVer = "5.1" Or osVer = "5.2" Then | |
strKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" | |
strVal = "DefaultUserName" | |
strValVal = "" | |
ElseIf osVer = "6.1" Then | |
If WScript.Arguments.Count = 0 Then | |
Set objAShell = CreateObject("Shell.Application") | |
objAShell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """" & " uac", "", "runas", 1 | |
WScript.Quit | |
Else | |
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" | |
strVal = "LastLoggedOnUser" | |
strValVal = "" | |
End If | |
Else | |
WScript.Echo "This OS is not supported by this script" | |
WScript.Quit | |
End If | |
On Error Resume Next | |
objWShell.RegWrite "HKLM\" & strKey & "\" & strVal, strValVal, "REG_SZ" | |
If Err = 0 Then | |
WScript.Echo "Logon Reset" | |
Else | |
WScript.Echo "Unable to reset logon" | |
End If |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment