我有一个脚本,可以运行该脚本来设置计算机以自动以管理员身份登录。我在这些计算机上使用 Vista Home Premium。我使用 MDT 2010 安装它们,安装完成后,我放置了一个脚本,通过写入注册表来设置自动管理员登录。
问题是由于某种原因,注册表中的键在重新启动后被重置。如果我再次运行脚本,它会起作用并且键不会被重置。(我让脚本在最后删除自身以加快工作流程)。
有谁知道为什么要重置密钥?
下面附上了我的脚本。
Option Explicit
Dim Temp
Dim oReg
Dim strComputer
Dim strResult
Dim intResult
Dim readValue
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strResult = ""
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Temp = WriteReg("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName","TobiiUser")
Temp = WriteReg("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword","Tobii")
Temp = WriteReg("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon","1")
Temp = WriteReg("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName",".")
Function WriteReg(strKeyPath, strValueName, strValue)
' Create key to use
intResult = oReg.CreateKey(HKEY_LOCAL_MACHINE, strKeyPath)
If (intResult = 0) And (Err.Number = 0) Then
' write string value to key
intResult = oReg.SetStringValue(HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
If (intResult = 0) And (Err.Number = 0) Then
intResult = oReg.GetStringValue(HKEY_LOCAL_MACHINE,strKeyPath,strValueName,readValue)
If readValue = strValue Then
strResult = strResult & "Succeded writing key: " & HKEY_LOCAL_MACHINE & strKeyPath & strValueName & VbCrLf
End If
Else
strResult = strResult & "Failed writing key: " & HKEY_LOCAL_MACHINE & strKeyPath & strValueName & " with error no: " & intResult & VbCrLf
End If
Else
strResult = strResult & "Failed creating key: " & HKEY_LOCAL_MACHINE & strKeyPath & strValueName & " with error no: " & intResult & VbCrLf
End If
End Function
'Delete the script
DeleteSelf
MsgBox strResult, vbInformation, "Autologon"
Sub DeleteSelf()
Dim objFSO
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Delete the currently executing script
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
End Sub
答案1
问题是 AutoLogonCount 为 0,如果为零,Windows 会在关机时清除 DefaultPassword 并将 AutoAdminLogon 设置为 0,因此会删除我最近的更改。解决方案是删除键 AutoLogonCount。