posts - 12,comments - 0,trackbacks - 0

'Code used to modify machine regeditry

Const HKEY_CLASSES_ROOT=&H80000000
Const HKEY_CURRENT_USER=&H80000001
Const HKEY_LOCAL_MACHINE=&H80000002
Const HKEY_USERS=&H80000003
Const HKEY_CURRENT_CONFIG=&H80000005
Const HKEY_DYN_DATA=&H80000006

Set objWshNet = CreateObject("Wscript.Network")
strServer = objWshNet.ComputerName

paraCount=WScript.Arguments.Count
If paraCount <> 7 Then
         Wscript.Echo "Usage:"
         Wscript.Echo "cscript //nologo ModifyRegistry.vbs /Machine:<MachineName> /Admin:<AdministratorName> /Pwd:<Passworkd> /DefKey:<definekey> /SubKeyName:<SubKey> /ValueName:<ValueName> /Value:<value>"
Else
         strComputer = Wscript.Arguments.Named.Item("Machine")
         strAdmin = Wscript.Arguments.Named.Item("Admin")
         strPassword = Wscript.Arguments.Named.Item("Pwd")
         strDefKey = Wscript.Arguments.Named.Item("DefKey")
         strSubKeyName = Wscript.Arguments.Named.Item("SubKeyName")
         strValueName = Wscript.Arguments.Named.Item("ValueName")
         strValue = Wscript.Arguments.Named.Item("Value")
        
         Set objLocator = CreateObject("WbemScripting.SWbemLocator")
         If UCase(strComputer) = UCase(strServer) Then        
           Set objService = objLocator.ConnectServer(, "Root\DEFAULT")
         Else
           Set objService = objLocator.ConnectServer(strComputer, "Root\DEFAULT", strAdmin,strPassword)
         End If
      
         Set objRegistry = objService.Get("StdRegProv")      
        
         If UCase(strDefKey)="HKEY_CLASSES_ROOT" Then
           Return = objRegistry.SetStringValue(HKEY_CLASSES_ROOT,strSubKeyName,strValueName,strValue)
         End If
        
         If UCase(strDefKey)="HKEY_CURRENT_USER" Then
           Return = objRegistry.SetStringValue(HKEY_CURRENT_USER,strSubKeyName,strValueName,strValue)
         End If
        
         If UCase(strDefKey)="HKEY_LOCAL_MACHINE" Then
           Return = objRegistry.SetDWORDValue(HKEY_LOCAL_MACHINE,strSubKeyName,strValueName,strValue)
         End If
        
         If UCase(strDefKey)="HKEY_USERS" Then
           Return = objRegistry.SetDWORDValue(HKEY_USERS,strSubKeyName,strValueName,strValue)
         End If
        
         If UCase(strDefKey)="HKEY_CURRENT_CONFIG" Then
           Return = objRegistry.SetStringValue(HKEY_CURRENT_CONFIG,strSubKeyName,strValueName,strValue)
         End If
        
         If UCase(strDefKey)="HKEY_DYN_DATA" Then
           Return = objRegistry.SetStringValue(HKEY_DYN_DATA,strSubKeyName,strValueName,strValue)
         End If
        
       
         If (Return = 0) And (Err.Number = 0) Then
             Wscript.Echo "Success."
       Else
           Wscript.Echo "Failed,Error = " & Err.Number
         End If
End If


'Code used to set remote
cscript //nologo ModifyRegistry.vbs /Machine:testmachine1 /Admin:domain\user1 /Pwd:100$apple  /DefKey:HKEY_LOCAL_MACHINE /SubKeyName:"SYSTEM\CurrentControlSet\Control\Terminal Server" /ValueName:fDenyTSConnections /Value:0

posted on 2007-04-29 13:38 GuangMing Lan 阅读(190) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。