Wednesday, January 19, 2011

Error with Auto admin logon in Vista

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
  • Hi, did you solve your problem? I ask you, because i've the same problem and for the moment i'm not able to go out from this impasse! thanks

    Ola : Yes I did! It was a problem with that I had the registry value AutoLogonCount = 0, while shutting down windows checks if this is equal 0 and if so it clears DefaultPassword and sets AutoAdminLogon to 0. So make sure to delete the key AutoLogonCount. /Ola
  • The problem was that AutoLogonCount was 0, if it is zero windows clears DefaultPassword and sets AutoAdminLogon to 0 at shutdown therefore removing my recent changes. The Solution was to delete the key AutoLogonCount.

    From Ola
  • Thank you... i just try it and it solve my problem!

0 comments:

Post a Comment