jonbutterworth
IS-IT--Management
Hey Guys,
I have the following code for changing the IP Address, which seems to do nothing on my Windows 7 Machine when I test it.
And also, I am trying to create another script that will set the DNS Address settings back to Automatic.
Basically I have a temporary issue where users need a different DNS Server in the office to get email to work but then when they go to work from home, they will need to set it back to automatic to get the internet working at home.
I have found multiple scripts that say they set the address manually, although I am unable to get it to work! But I cannot find anything that will set it back to Automatic.
Ideally I'd like to have 2 x Icons on the users desktop, one saying Office and one Saying home, the office one sets the static DNS Server Address and the home one sets the automatic DNS Server address.
The code I have for setting the static address is as follows:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")
For Each objNetCard in colNetCards
If objNetCard.DHCPEnabled = True Then
object.Skip(3)
Else
arrDNSServers = Array("192.168.1.1", "192.168.1.2")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
End If
Next
Using 1.1 and 1.2 as test servers for this laptop, but will change them to the correct servers when I know its working.
Any help would be greatly appreciated.
Thanks,
Jon
I have the following code for changing the IP Address, which seems to do nothing on my Windows 7 Machine when I test it.
And also, I am trying to create another script that will set the DNS Address settings back to Automatic.
Basically I have a temporary issue where users need a different DNS Server in the office to get email to work but then when they go to work from home, they will need to set it back to automatic to get the internet working at home.
I have found multiple scripts that say they set the address manually, although I am unable to get it to work! But I cannot find anything that will set it back to Automatic.
Ideally I'd like to have 2 x Icons on the users desktop, one saying Office and one Saying home, the office one sets the static DNS Server Address and the home one sets the automatic DNS Server address.
The code I have for setting the static address is as follows:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")
For Each objNetCard in colNetCards
If objNetCard.DHCPEnabled = True Then
object.Skip(3)
Else
arrDNSServers = Array("192.168.1.1", "192.168.1.2")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
End If
Next
Using 1.1 and 1.2 as test servers for this laptop, but will change them to the correct servers when I know its working.
Any help would be greatly appreciated.
Thanks,
Jon