Configure Network Cards

Configure Network Cards

Post by anthon » Sun, 05 Dec 2004 05:19:38


I am trying to configure my network card with a script. I have it set to
configure the card with a static IP, but now I need to gather user
input to get the IP they may need. Below is the script that works and
mine that does not. I am a big time newbie for scripting so please bear
with me.

Thanks in advance
Tony

Old Script that works:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from
Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.0.100")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("0.0.0.0")
strGatewayMetric = Array(1)

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
Exit For
Next

New Script that does NOT work:


strComputer = "."
Dim NewIP , NewSubnet
NewIP = InputBox ("Please enter the IP Address for this Computer",
"Enter Network IP Address", "192.168.0.100")
NewSubnet = InputBox ("Please enter the Subnet Mask for this Computer",
"Enter Network Subnet Mask", "255.255.255.0")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery ("Select * from
Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = NewIP
strSubnetMask = NewSubnet
strGateway = Array("0.0.0.0")
strGatewayMetric = Array(1)

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
Exit For
Next