' 01 输入计算机编号
strIP = InputBox("Enter IP Name",title,"", 3200, 3200)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("100.100.1."&strIP)
strSubnetMask = Array("255.255.0.0")
strGateway = Array("100.100.100.1")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
Next
' 02 修改固定DNS
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
arrDNSServers = Array("100.100.11.1")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next
' 03 修改固定winsserver
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
strPrimaryServer = "100.100.11.1"
strSecondaryServer = " "
objNetCard.SetWINSServer strPrimaryServer, strSecondaryServer
Next
' 04 修改计算机名为PCxxx
Name = "PC"&strIP
Password = "ppp"
Username = "administrator"
Set objWMIService = GetObject("Winmgmts:root\cimv2")
' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in _
objWMIService.InstancesOf("Win32_ComputerSystem")
Return = objComputer.rename(Name,Password,User)
Next
' 05 修改计算机名后缀
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\ControlSet001\Services\Tcpip\Parameters"
strValueName = "NV Domain"
strValue = "dns name"
Return = objReg.SetStringValue( _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
If (Return = 0) And (Err.Number = 0) Then
End If
' 06 修改dns后缀
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
arrDNSSuffixes = Array("global.test.com", "global.arup.com")
objNetworkSettings.SetDNSSuffixSearchOrder(arrDNSSuffixes)
' 07 修改dns名
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
objNetCard.SetDNSDomain("test.com")
Next
' 08
strComputer = "."
Set ooReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\ControlSet001\Services\Tcpip\Parameters"
strValueName = "SyncDomainWithMembership"
ooReg.SetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,0
If Err = 0 Then
ooReg.GetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
End If
' 09
strComputer = "."
Set oooReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\ControlSet001\Services\Tcpip\Parameters"
strValueName = "SyncDomainWithMembership"
oooReg.SetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,0
If Err = 0 Then
End If
' 10
strComputer = "."
Set ooooReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces"
ooooReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
' subkey就是目录名字
strKeyPath2 = "SYSTEM\ControlSet001\Services\Tcpip\Parameters\Interfaces\" & subkey
strValueName2 = "RegisterAdapterName"
ooooReg.SetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath2,strValueName2,1
Next
' 11 wait
WScript.Sleep(90000)
' 12 create regedit
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
strValueName = "BAT"
strValue = "C:\temp\1.5.vbs"
Return = objReg.SetStringValue( _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
' 13 restart
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
本文出自 “Johnny” 博客,谢绝转载!