Changing Computers IP Addresses with VBScript

So now that we changed the machine name and user names we might need to change some IP’s….

As you can see below you will need to specify the IP’s somehow (hard coded right now) with a MSGBOX, Registry read, text file, Machine name etc

'----------------------------------------------------------------------

	const HKLM   = &H80000002
	
	Set WshShell = CreateObject("WScript.Shell")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set oNetwork = CreateObject("WScript.Network")
	
	strCurrentComputerName = oNetwork.ComputerName

	'Setup IP's you want to implament, you can add logic for MSGBOX etc.		
		strComputer = "."
		IPAddress = "10.11.12.13"
		dGateway = "10.11.12.11"
		arrIPAddress = Array(IPAddress)
		arrSubnetMask = Array("255.255.255.128")
		arrGateway = Array(dGateway)
		arrDNSServers = Array("12.107.200.146")
		
		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)
		     errGateways = objNetAdapter.SetGateways(arrGateway)
		     intSetDNSServers = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
		Next
	
		If intSetDNSServers = 0 Then
		    MSGBOX("Server IPs set to: IPAddress = " & IPAddress)
		Else
			MSGBOX("Error setting server info.")
	 	End If
This entry was posted in Scripting and tagged , , , , . Bookmark the permalink.
  • Pingback: Google Analytics Search Terms For My Sites - Yeshai Bouskila()

  • mohamed

    hi

    good script, can you tel me how can i change diffrerent ipadress for

    differents adapters. for exemple i have 2 adapters in may PC.

    thanks

  • Yeshaib™

    If you look at my script it will change one adapter, you could do this in a different way if you know the adapters name
    Like
    Local Area Connection 1
    Local Area Connection 2
    Etc
    Let me know if that will work for you and I’ll post something

  • Descent

    Well, “enjoying” this article is a bit strong verb for my feelings :) , but it gives a good example for setting IP properties via WMI.

    Grats.