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.