' 01 输入计算机编号
strIP = InputBox("Enter IP Name",title,"", 3200, 3200)

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\" & strComputer & " ootcimv2")
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 & " ootcimv2")
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 & " ootcimv2")
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:rootcimv2")
' 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 & " ootdefault:StdRegProv")
strKeyPath = "SYSTEMControlSet001ServicesTcpipParameters"

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 & " ootcimv2")
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 & " ootcimv2")
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 & " ootdefault:StdRegProv")

strKeyPath = "SYSTEMControlSet001ServicesTcpipParameters"

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 & " ootdefault:StdRegProv")

strKeyPath = "SYSTEMControlSet001ServicesTcpipParameters"

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 & " ootdefault:StdRegProv")

 strKeyPath = "SYSTEMControlSet001ServicesTcpipParametersInterfaces"

ooooReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

 For Each subkey In arrSubKeys

' subkey就是目录名字

 strKeyPath2 = "SYSTEMControlSet001ServicesTcpipParametersInterfaces" & 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 & " ootdefault:StdRegProv")

strKeyPath = "SOFTWAREMicrosoftWindowsCurrentVersionRun"

strValueName = "BAT"

strValue = "C: emp1.5.vbs"
Return = objReg.SetStringValue( _

        HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue)
' 13 restart


Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate,(Shutdown)}!\" & _

        strComputer & " ootcimv2")
Set colOperatingSystems = objWMIService.ExecQuery _

    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems

    objOperatingSystem.Reboot()

Next