Complete newbie here, this is a bit of frankenstein of various scripts that I've found (not sure if it's 'proper', but it works, any pointers I'd be appreciative!).
Background:
I work for a school and needed a script to run for the teachers with laptops to be able to use them at home (with no proxy server set), and in school (with a proxy server)
This is my first script, so please be gentle ;)
Oh, and hello everyone :D
'Triggers a 5 second pause in order for logon scripts & printer batch files to run.
WSCript.Sleep 5000
On Error Resume Next
Dim refWMI,sIPAddress,colNetworkAdapters,oNetworkAdapter,sIPSubnet,WshShell,sProxyPort
'Runs script on local computer.
strComputer = "."
'Specifies the beginning ip for schools network.
sIPSubnet = "172."
'Change values for proxy settings
sProxyURL = "proxy.server.address.here"
sProxyPort = "proxy.port.here"
'Finds IP addresses of all network adapters on machine and stores in sIPAddress
Set refWMI = GetObject("WinMgmts:\\.\root\cimv2")
Set colNetworkAdapters = refWMI.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Set WshShell = CreateObject("Wscript.Shell")
For Each oNetworkAdapter in colNetworkAdapters
If oNetworkAdapter.IPAddress(0) <> "0.0.0.0" Then
sIPAddress = oNetworkAdapter.IPAddress(0)
Exit For
End If
Next
'Checks to see if the IP address begins with 172.
If InStr(sIPAddress,sIPSubnet) Then
'If true then sets proxy settings specified above.
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer",sProxyURL & ":" & sProxyPort,"REG_SZ"
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable",1,"REG_DWORD"
'If true then sets internet explorer home page to intranet site.
strKeyPath = "SOFTWARE\Microsoft\Internet Explorer\Main"
ValueName = "Start Page"
strValue = "[link=http://intranetaddress.int]http://intranetaddress.int[/link]"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
Else
'If false then clears proxy settings flag to none.
WshShell.RegDelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer"
WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable",0,"REG_DWORD"
'If false then sets internet explorer home page to external site.
strKeyPath = "SOFTWARE\Microsoft\Internet Explorer\Main"
ValueName = "Start Page"
strValue = "[link=http://externaladdress.org.uk]http://externaladdress.org.uk[/link]"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
MsgBox"Internet Explorer Setting Change Completed", vbInformation, "Complete"
End If
'Cleanup
Set refWMI = Nothing
Set colNetworkAdapters = Nothing
Set WshShell = Nothing
Const HKEY_CURRENT_USER = &H80000001