I have a script that I run to set up computers to auto login as administrator. I use Vista home premium on these computers. I install them with MDT 2010 and after that is finished I have placed a script that I run to set auto admin logon by writing to the registry.
The problem is that for some reason the keys in the registry is reset after a reboot. If I run the script once again it works and the keys are not reset. (I make the script delete itself at the end to make the workflow faster).
Does anyone know why the keys are reset?
I include my script below.
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