Skip to content

Instantly share code, notes, and snippets.

@umer936
Created August 10, 2016 15:50
Show Gist options
  • Save umer936/d6106ababde4427c7fbc845a660a8e10 to your computer and use it in GitHub Desktop.
Save umer936/d6106ababde4427c7fbc845a660a8e10 to your computer and use it in GitHub Desktop.
Option Explicit
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, WScript.ScriptFullName & " /elevate", "", "runas", 1
WScript.Quit
End If
On Error Resume Next
Dim objWMIService
Dim objNetAdapter
Dim strComputer
Dim arrIPAddress
Dim arrSubnetMask
Dim arrGateway
Dim colNetAdapters
Dim errEnableStatic
Dim errGateways
Dim strInput
Dim errFailed
errFailed = 0
strInput = InputBox("Type Static IP Address or AUTO")
If strInput = "AUTO" Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
If Not errEnable = 0 Then
WScript.Echo "Setting IP settings for you, my good sir."
errFailed = 1
End If
Next
Else
strComputer = "."
arrIPAddress = Array(strInput)
arrSubnetMask = Array("255.0.0.0")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
errEnableStatic = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
If Not errEnableStatic = 0 Then
WScript.Echo "Failure assigning IP/Subnet."
errFailed = 1
End If
errGateways = objNetAdapter.SetGateways(arrGateway)
If Not errGateways = 0 Then
WScript.Echo "Failure assigning Gateway."
errFailed = 1
End If
Next
End If
If errFailed = 0 Then
WScript.Echo "IP Settings Successfully Modified."
End If
WScript.Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment