Windows 7 - 用于更改上次登录用户的 VBS 脚本

ova*_*n86 5 windows-registry windows-7 login vbscript

在 Windows XP 中,我曾经在使用客户端计算机将其用户帐户设置为最后登录用户后运行 VBS 脚本。

不幸的是,该脚本在 Windows 7 中不再有效。(导致一些用户在尝试登录时锁定我的帐户并发现他们的密码与我的不同!)

这是我使用的脚本示例:

http://www.itsupportguides.com/vbs-scripts/using-vbs-to-set-the-last-user-logged-on-windows-xp

编辑:关于我们环境的附加信息

我们的环境:

  • 启用 UAC
  • 以“itsupport”帐户登录,该帐户是本地管理员组的成员
  • 现在所有系统都安装了 Windows 7 Enterprise
  • 所有系统都加入了一个 Active Directory 域

ova*_*n86 4

感谢那些帮助解决这个问题的人。

经过进一步研究,我发现 Windows 7 不使用相同的“Winlogon”注册表项来存储最后登录的用户,而是使用

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser
Run Code Online (Sandbox Code Playgroud)

我遇到的第二个问题是允许使 VBS 脚本以提升的用户(管理员)身份运行,而无需使用“runas”或提升的命令提示符。

经过一番尝试和错误后,我创建了以下脚本,该脚本成功更改了添加域的 Windows 7 工作站的最后登录用户。

希望这里的其他人会发现它有帮助 - 我知道我会的!

设置上次登录 - Win7.vbs

    '--------------
'Start of UAC workaround code

If WScript.Arguments.length =0 Then
  Set objShell = CreateObject("Shell.Application")

  objShell.ShellExecute "wscript.exe", Chr(34) & _
  WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else

'--------------
'Start of code

    dim WSHShell
    Set WSHShell = Wscript.CreateObject("WScript.Shell")
    dim strRegKey
    strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
    strRegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\"

    StrUser = InputBox("Please enter in username," & vbCrLf & vbCrLf & "e.g. joe.local", "Set Last logged on", "UserName")
    StrDomain = InputBox("Please enter in domain for logon," & vbCrLf & vbCrLf & "e.g. DOMAIN", "Set Logon Domain OR leave blank if a local user account")

    If StrDomain = "" then
         StrDomain = "."
       Else
    End If

    wshShell.RegWrite strRegKey & "LastLoggedOnUser", StrDomain & "\" & StrUser, "REG_SZ"

        WScript.Echo "Setup Completed. Please restart the computer to complete the process"

    '--------------
    'End of code


    '--------------
    'End of UAC workaround code

    End If
Run Code Online (Sandbox Code Playgroud)

完整来源:Windows 7 - 用于更改上次登录用户的 VBS 脚本