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

Change Proxy Settings

Last post 08-16-2007, 2:41 PM by jeppolito. 4 replies.
Sort Posts: Previous Next
  •  08-16-2007, 2:41 PM 4573

    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



  •  08-25-2007, 2:33 PM 4603 in reply to 4573

    Re: Change Proxy Settings

    Hi jeppolito,

    I wonder if proxy auto detect would work for you. I have used it with ISA Server and it works quite well. Basically, if the client detects the proxy server, it will use it; otherwise, it will connect directly.

    HTH,

    Bill

  •  08-27-2007, 9:47 AM 4608 in reply to 4603

    Re: Change Proxy Settings

    Thanks for the suggestion AbqBill.  I will look this up. I am also considering software such as "netswitcher" but thought a script might be better and definitely cheaper.  BTW the error I am receiving is a syntax error on line 19, char 64, source MS VBScript Compilation Error. Thanks again.

                                                          James
     

  •  08-28-2007, 8:29 AM 4613 in reply to 4608

    Re: Change Proxy Settings

    Ok, I ran it against vbsedit and simply stated it didn't like the break on line 19 which was,
              If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable
    ",REG_DWORD) = 1 AND
              Len(GetValue(HKCU,HKCU_IE_PROXY,"ProxyServer",REG_SZ)) > 0 Then

    I changed it to:
     If GetValue(HKCU,HKCU_IE_PROXY,"ProxyEnable",REG_DWORD) = 1 AND Len(GetValue
    and that worked. There were a couple of other errors with spaces inserted which I repaired.  Thanks to all who posted.
  •  08-28-2007, 2:42 PM 4616 in reply to 4613

    Re: Change Proxy Settings

    BTW if anyone comes across a Powershell script for changing the proxy settings please let me know. I may write one over the next week and post it here.
View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Microsoft Learning Snack - Green IT Through Virtualization Many organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. Order Your Fundamentals CD Today!Register today for your in-depth copy of one of three Fundamental CDs on the following topics – Exchange, SQL, and SharePoint. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Empower Your Processes with PowerShell 201Paul Robichaux delves deep into PowerShell how-tos in 3 informative lessons, each followed by live Q&A—all on your own computer! Register today! Microsoft Learning Snack - Green IT Through VirtualizationMany organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. New Release: Windows IT Pro Master CD13 years of content archives, fast answers with advanced search tools, and full access to WindowsITPro.com—order today!

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