Войти

Показать полную графическую версию : Помогите со скриптом? VBScript


voler
09-06-2007, 10:37
Есть скрипт позволяющий менять IP на удаленной машине.

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
Нужно внести в скрипт вместо strIPAddress = Array("192.168.1.71")
IstrIPAddress = inputBox("Введите IP:")
и т.п.

voler
09-06-2007, 11:22
Проделал как написал.

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
Если скрипт весь, то в первой строке должно стоять либо имя удаленного ПК, либо IP адрес=>
либо нужно заменить strComputer = "." на strComputer = inputBox("Введите имя ПК:"), либо прописать имя ПК вместо "."

voler
09-06-2007, 12:24
Таже ситуация.

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
strIPAddress = Array(inputBoxinputBox("Введите IP?:"))
strSubnetMask = Array(inputBox("Введите Mask?:"))
strGateway = Array(inputBox("Введите Gateway?:"))

Вот в таком виде у меня работает.

voler
09-06-2007, 14:54
Выкладываю рабочий скрипт. Спасибо тебе Gerdewski.

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

Решено можно закрывать тему.

voler
09-06-2007, 15:13
Думаю может еще добавить смену dns?

For Each objNetCard in colNetCards
arrDNSServers = Array("192.168.1.100")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)

Вот только нужно это или нет, смена dns сервера как правило нужна в больших сетях. Мне пока не к чему.




© OSzone.net 2001-2012