弹出 YES or NO 的对话框,不同的选择执行不同的代码
intAnswer=Msgbox("你是否要对你的机器的计算机名及IP进行改动?",vbYesNo," 机器名,IP,网关,掩码,DNS修改器")
If intAnswer=vbYes Then
set objShell=wscript.createObject("wscript.shell")
Set WshNetwork = CreateObject("WScript.Network")
computerName=InputBox("原机器名为:"&WshNetwork.ComputerName&""&vbCr&vbCr&"请输入计算机名:"&vbCr&vbCr&"显示器上的数字"&vbCr&vbCr&"计算机名:","计算机IP地址修改工具",""&WshNetwork.ComputerName&"")
IPAddress=InputBox("请输入IP地址:"&vbCr&vbCr&"10.154.63 开头,机器名加10"&vbCr&vbCr&"IP地址:","IP地址修改工具",user)
NetMask=InputBox("请输入子网掩码地址:"&vbCr&vbCr&"255.255.255.0开头"&vbCr&vbCr&"子网掩码地址:","IP地址修改工具","255.255.255.0")
Gateway=InputBox("请输入网关地址:"&vbCr&vbCr&"10.154.63.1 默认"&vbCr&vbCr&"网关地址:","IP地址修改工具","10.154.63.1")
NameServer=InputBox("请输入DNS地址:"&vbCr&vbCr&"10.152.8.100默认"&vbCr&vbCr&"DNS地址:","IP地址修改工具","10.152.8.100")

'设置计算机名
Dim WSH
Set WSH = CreateObject("Wscript.Shell")
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ComputerName\ComputerName",computerName,"REG_SZ"
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName\ComputerName",computerName,"REG_SZ"
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\NV Hostname",computerName,"REG_SZ"
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters\Hostname",computerName,"REG_SZ"
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Control\ComputerName\ComputerName\ComputerName",computerName,"REG_SZ"
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Services\Tcpip\Parameters\NV Hostname",computerName,"REG_SZ"
WSH.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet003\Services\Tcpip\Parameters\Hostname",computerName,"REG_SZ"

'设置IP地址
strIPAddress = Array(""&IPAddress&"") '修改后的ip
strSubnetMask = Array(""&NetMask&"") '子网掩码
strGateway = Array(""&Gateway&"") '网关
arrDNSServers = Array(""&NameServer&"")'DNS
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter in colNetAdapters
sip=objNetAdapter.IPAddress
'strIPAddress = sip '保持原来的ip

strGatewayMetric = Array(1)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS=objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "你的计算机名为 "&computerName&"你的IP地址已经改成: "&IPAddress&"","子网掩码地址已经改成: "&NetMask&"","网关地址已经改成: "&Gateway&"","DNS地址已经改成: "&NameServer&""
Else
WScript.Echo "你没有修改你的设置."
End If
exit for '只修改第一个网卡的设置
Next


Else
Msgbox "你选择了不设置,拜拜。",48," 机器名,IP,网关,掩码,DNS修改器"
End If

arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()