|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Need to allow user to toggle Network IP Addresses
Hi:
I have a user who needs to be able to use one static ip address on a network for her laptop, and another static ip address for a different network. How would you guys approach writing a script which could be used to toggle between the two ip addresses? I found an article for a VBS script that claimed to be able to do this. Does the code look good to you? Code:
Set oLocator = New SWbemLocator
Set oServices = oLocator.ConnectServer(, "root\cimv2")
Set oObject = oServices.Get("Win32_NetworkAdapterConfiguration.Index=0")
Dim asIPAddress
Dim asSubnetMask
asIPAddress = Array("xxx.xxx.xxx.xxx")
asSubnetMask = Array("xxx.xxx.xxx.xxx")
Set oMethod = oObject.Methods_("EnableStatic")
Set inParam = oMethod.InParameters.SpawnInstance_()
inParam.IPAddress = asIPAddress
inParam.SubnetMask = asSubnetMask
Set outParam = oObject.ExecMethod_("EnableStatic", inParam)
If outParam.returnValue = 0 Then
MsgBox "Method Succeeded."
Else
MsgBox "Method Failed. " & CStr(outParam.returnValue)
Thank you very much for any pointers. Mike |
|
#2
|
|||
|
|||
|
Hi, so when I run this:
Code:
Set oLocator = CreateObject("WbemScripting.SWbemLocator") 'New SWbemLocator
Set oServices = oLocator.ConnectServer(,"root\cim2") '(,"root\default")
Set oObject = oServices.Get("Win32_NetworkAdapterConfiguration.Index=0")
Dim asIPAddress
Dim asSubnetMask
asIPAddress = Array("xxx.xxx.138.47")
asSubnetMask = Array("255.255.255.0")
Set oMethod = oObject.Methods_("EnableStatic")
Set inParam = oMethod.InParameters.SpawnInstance_()
inParam.IPAddress = asIPAddress
inParam.SubnetMask = asSubnetMask
Set outParam = oObject.ExecMethod_("EnableStatic", inParam)
If outParam.returnValue = 0 Then
MsgBox "Method Succeeded."
Else
MsgBox "Method Failed. " & CStr(outParam.returnValue)
End If
The error message i get is: Script:\ChangeIPAddress.vbs Line: 2 Char: 1 Error: Invalid Namespace Code: 8004100E Source: SWbemLocator Anyone able to work on this with me? Much thanks. Mike |
![]() |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Need to allow user to toggle Network IP Addresses |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|