怎么更改计算机wmi配置,用WMI修改计算机名和IP

' 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” 博客,谢绝转载!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值