2014年6月25日 星期三

Auto logon(2):Create auto logon with WMI by using VB Script

''''''Sample code如下''''''''

'Set wshShell = WScript.CreateObject( "WScript.Shell" )
'strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set oNetwork = CreateObject("wScript.Network")
strComputerName=oNetwork.Computername         
strDefaultUserName="test6"
strDefaultPassword="pwd6"
strGroup="administrators"
strAutoAdminLogon="1"


function create_user_ADSI()
Set objou=GetObject("WinNT://" & strComputerName & "")
Set objuser=objou.Create("user", strDefaultUserName)
objuser.SetPassword(strDefaultPassword)
objuser.SetInfo

'''''''''''set administrator group touser account
Set objou=GetObject("WinNT://" & strComputerName & "/" & strGroup & ",group")
objou.add("WinNT://" & strComputerName & "/" & strDefaultUserName  & ",user")
end function


function add_autologon()
      'Set-Location=WriteReg(HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon")
      'RegPath=
      Set wshShell = WScript.CreateObject( "WScript.Shell" )
     
      wshShell.RegWrite "HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon\AutoAdminLogon","1","REG_SZ"
'      WScript.Echo(wshShell.RegRead ("HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon\AutoAdminLogon"))
      wshShell.RegWrite "HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon\DefaultUserName", strDefaultUserName ,"REG_SZ"
      wshShell.RegWrite "HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon\DefaultPassword", strDefaultPassword ,"REG_SZ"
    
      on Error Resume Next
        AutoLogonCountValue=wshShell.RegRead ("HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon\AutoLogonCount")
      if Err.Number = 0 then
         KeyExist=true
      else
         KeyExist=False  ''''''registry key is not exist
      end if
      if ( AutoLogonCountValue And KeyExist )  then
       wshShell.RegWrite "HKLM\Software\Microsoft\Windows NT\Currentversion\WinLogon\AutoLogonCount", AutoLogonCountValue,"REG_DWORD"
      END IF
end function

沒有留言:

張貼留言