Welcome to Scripting Forums Sign in | Join | Help
in Search

Change Proxy Settings

Last post 08-16-2007, 8:21 AM by jeppolito. 0 replies.
Sort Posts: Previous Next
  •  08-16-2007, 8:21 AM 4570

    Change Proxy Settings

    I need to create a script which would disable the proxy settings (IE, Tools, Internet Options, Connections, LAN Settings) so when user connect via a laptop or table they can use the script to remove the proxy settings. I would like the script to add the proxy back as well, however, since this is currently being done via GPO when they connect inside the network this is not imperitive.  I would also like to see how this script would look/work with Powershell instead of VBScript.  I have created a vbscript (pasted below) but I cannot get it to work:


    Const HKCU=&H80000001 'HKEY_CURRENT_USER
    Const HKLM=&H80000002 'HKEY_LOCAL_MACHINE

    Const REG_SZ=1
    Const REG_EXPAND_SZ=2
    Const REG_BINARY=3
    Const REG_DWORD=4
    Const REG_MULTI_SZ=7

    Const HKCU_IE_PROXY = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"

    Set oReg=GetObject("winmgmts:!root/default:StdRegProv")

    Main

    Sub Main()

    ' If Proxy is set then turn it off
    If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable",REG_DWORD) = 1 AND
    Len(GetValue(HKCU,HKCU_IE_PROXY,"ProxyServer",REG_SZ)) > 0 Then
    CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",0,REG_DWORD
    wscript.echo "Proxy Disabled"
    Else
    ' If Proxy is not set then turn it on

    strProxyServer = "192.168.XXX.XXX:8080"
    strProxyOveride = "*.city.XXX"

    CreateValue HKCU,HKCU_IE_PROXY,"ProxyServer",strProxyServer,REG_SZ
    CreateValue HKCU,HKCU_IE_PROXY,"ProxyEnable",1,REG_DWORD
    CreateValue HKCU,HKCU_IE_PROXY,"ProxyOverride",strProxyOveride,REG_SZ
    wscript.echo "Proxy Enabled" & vbcrlf & "(" & strProxyServer & ")"
    End If

    End Sub

    Function CreateValue(Key,SubKey,ValueName,Value,KeyType)
    Select Case KeyType
    Case REG_SZ
    CreateValue = oReg.SetStringValue(Key,SubKey,ValueName,Value)
    Case REG_EXPAND_SZ
    CreateValue =
    oReg.SetExpandedStringValue(Key,SubKey,ValueName,V alue)
    Case REG_BINARY
    CreateValue = oReg.SetBinaryValue(Key,SubKey,ValueName,Value)
    Case REG_DWORD
    CreateValue = oReg.SetDWORDValue(Key,SubKey,ValueName,Value)
    Case REG_MULTI_SZ
    CreateValue =
    oReg.SetMultiStringValue(Key,SubKey,ValueName,Valu e)
    End Select
    End Function

    Function DeleteValue(Key, SubKey, ValueName)
    DeleteValue = oReg.DeleteValue(Key,SubKey,ValueName)
    End Function

    Function GetValue(Key, SubKey, ValueName, KeyType)

    Dim Ret

    Select Case KeyType
    Case REG_SZ
    oReg.GetStringValue Key, SubKey, ValueName, Value
    Ret = Value
    Case REG_EXPAND_SZ
    oReg.GetExpandedStringValue Key, SubKey, ValueName, Value
    Ret = Value
    Case REG_BINARY
    oReg.GetBinaryValue Key, SubKey, ValueName, Value
    Ret = Value
    Case REG_DWORD
    oReg.GetDWORDValue Key, SubKey, ValueName, Value
    Ret = Value
    Case REG_MULTI_SZ
    oReg.GetMultiStringValue Key, SubKey, ValueName, Value
    Ret = Value
    End Select

    GetValue = Ret
    End Function



View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Free Download –VS 2008 TrainingExperts Ken Getz & Robert Green plus labs, code, courseware Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Register for SolarWinds VM MonitorGet X-Ray Vision into Your ESX Servers with SolarWinds FREE VM Monitor GoGrid Offers FREE Trial for Windows Cloud ServersDeploy Windows Server 2003 and 2008 with free load balancing through GoGrid’s award winning web-based GUI – all in less than 5 minutes Order Your SQL Fundamentals CD Today! Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD. How healthy is your Exchange Server? Find out Now!Automatic Exchange Server Maintenance helps prevent disasters and improves performance. Download a FREE Exchange Server analysis tool. You've Deployed SharePoint...Now What?This one-day free online conference delivers the technical knowledge needed to kick MOSS up a notch. In one information-packed day, independent SharePoint experts will present practical, real-world information and provide take-away, ready-to-use solutions Ease Your Scripting Pains with the Flexibility of PowerShell!Paul Robichaux equips you with PowerShell basics in 3 introductory lessons, each followed by live Q&A—all on your own computer! Register today! What Would You Do If You Ran Microsoft?ITTV's 2008 inaugural video contest, "If I Ran Microsoft..." is your chance to tell it like it is. Be goofy or be serious, but don"t miss this chance to have fun, win prizes, and go viral in a major way. Maximize Your SharePoint InvestmentThis web seminar discusses how true bi-directional replication of SharePoint content from one server to another enables branch offices to maintain access to current SharePoint content. Rock Your Knowledge, and Compete with Friends and Colleagues!Are you the Web Application Performance Guru in your office? It's time to have fun! Download now to access the crossword puzzle. Challenge yourself and complete this fun activity!

 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing