Помогите со скриптом? VBScript
Есть скрипт позволяющий менять IP на удаленной машине.
HTML код:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.71")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
Подскажите как можно подделать так чтобы
strComputer, strIPAddress, strSubnetMask, strGateway вводить в интерактивном режиме, с использванием InputBox и MsgBox ?
|
Gerdewski |
09-06-2007 10:58 597256 |
Нужно внести в скрипт вместо strIPAddress = Array("192.168.1.71")
IstrIPAddress = inputBox("Введите IP:")
и т.п.
|
Проделал как написал.
HTML код:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
IstrIPAddress = inputBox("Введите IP?:")
strIPAddress = Array("IstrIPAddress")
IstrSubnetMask = inputBox("Введите Mask?:")
strSubnetMask = Array("IstrSubnetMask")
IstrGateway = inputBox("Введите Gateway?:")
strGateway = Array("IstrGateway")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
Пишет IP не установлен. Где то трабла.
|
Gerdewski |
09-06-2007 11:30 597269 |
Если скрипт весь, то в первой строке должно стоять либо имя удаленного ПК, либо IP адрес=>
либо нужно заменить strComputer = "." на strComputer = inputBox("Введите имя ПК:"), либо прописать имя ПК вместо "."
|
Таже ситуация.
HTML код:
IstrComputer = inputBox("Введите Network Name Computer?:")
Set objWMIService = GetObject("winmgmts:\\" & IstrComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
IstrIPAddress = inputBox("Введите IP?:")
strIPAddress = Array("IstrIPAddress")
IstrSubnetMask = inputBox("Введите Mask?:")
strSubnetMask = Array("IstrSubnetMask")
IstrGateway = inputBox("Введите Gateway?:")
strGateway = Array("IstrGateway")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
|
Gerdewski |
09-06-2007 14:10 597349 |
strIPAddress = Array(inputBoxinputBox("Введите IP?:"))
strSubnetMask = Array(inputBox("Введите Mask?:"))
strGateway = Array(inputBox("Введите Gateway?:"))
Вот в таком виде у меня работает.
|
Выкладываю рабочий скрипт. Спасибо тебе Gerdewski.
HTML код:
strComputer = inputBox("Введите имя ПК:") 'Вводим имя компьютера
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array(inputBox("Введите IP?:")) 'Вводим IP новый.
strSubnetMask = Array(inputBox("Введите Mask?:")) 'Вводим новую Mask.
strGateway = Array(inputBox("Введите Gateway?:")) 'Вводим новый шлюз
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
Решено можно закрывать тему.
|
Думаю может еще добавить смену dns?
For Each objNetCard in colNetCards
arrDNSServers = Array("192.168.1.100")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Вот только нужно это или нет, смена dns сервера как правило нужна в больших сетях. Мне пока не к чему.
|
Время: 07:18.
© OSzone.net 2001-