Welcome !

 Change Proxy Settings dependant on ipaddress

Author Message

  • Total Posts : 18
  • Scores: 0
  • Reward points : 0
  • Joined: 10/21/2007
  • Location: Solihull, UK
  • Status: offline
Change Proxy Settings dependant on ipaddress Wednesday, October 24, 2007 9:40 PM (permalink)
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!).
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) <> "" Then
             sIPAddress = oNetworkAdapter.IPAddress(0)
             Exit For
       End If
 '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
       '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
 Set refWMI = Nothing
 Set colNetworkAdapters = Nothing
 Set WshShell = Nothing
 Const HKEY_CURRENT_USER = &H80000001

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2017 ASPPlayground.NET Forum Version 3.9