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 = ""
		dGateway = ""
		arrIPAddress = Array(IPAddress)
		arrSubnetMask = Array("")
		arrGateway = Array(dGateway)
		arrDNSServers = Array("")
		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)
		If intSetDNSServers = 0 Then
		    MSGBOX("Server IPs set to: IPAddress = " & IPAddress)
			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


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

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


  • 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
    Local Area Connection 1
    Local Area Connection 2
    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.