Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Proxy for home and work 1

Status
Not open for further replies.

FISKO

Technical User
Aug 30, 2005
113
0
0
GB
Hi I have started a script which I hope to use on users laptops to allow a simple solution to change the proxy settings for work and home. It sort of works but sometimes fails could someone take a look and point me in the right direction.Script below

<Dim objWSch
Set objWSch = Wscript.CreateObject("Wscript.Shell")
Set ShellObj = WScript.CreateObject("WScript.Shell")

Dim strProxy, strNewProxy
strProxy = objWSch.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer")

If strProxy=" : " Then
strNewProxy = "proxy.gfl.suffolk.xxx.xxx:8084"
Else

ShellObj.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer", " : "
ShellObj.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable",0
End if

objWSch.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer",strNewProxy
objWSch.Popup "Proxy is now " & strNewProxy, 3, "Swap Proxy Settings", 1

WScript.Quit>


THANKS

Only the GOOD die young,
Me? I'm here forever!
 
First, why are you declaring the shell object twice and with different variable names?

What is the point in your logic to set the proxy to ":" and then reset it to "proxy.gfl.suffolk.xxx.xxx:8084"?

This entire script could be condensed down to:

Code:
Set WSHShell = CreateObject("Wscript.Shell")
strNewProxy = "proxy.gfl.suffolk.xxx.xxx:8084"
        
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyServer",strNewProxy,"REG_SZ"
WSHShell.RegWrite Path & "ProxyEnable", 0 ,"REG_DWORD"

However I believe that you want to set ProxyEnable to 1 if you are setting a value to it. If your purpose is to just clear the Proxy information, then the following will do the trick.

Code:
[green]
'==========================================================================
'
' NAME:ClearProxy.vbs 
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.TheSpidersParlor.com[/URL]
' COPYRIGHT (c) 2006 All Rights Reserved
' DATE  : 5/25/2006
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'==========================================================================[/green]
 
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
Path = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
WshShell.RegWrite Path & "ProxyServer", vbNothing ,"REG_SZ"
WshShell.RegWrite Path & "ProxyEnable", 0 ,"REG_DWORD"
Set WSHShell = Nothing

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Markdmac, The idea was to allow the user to run the script and if the "proxy.gfl.xxx.xxx:8084" was set then it would remove this and uncheck the use proxy box. If the use proxy box was checked on the computer it would check it and add the "proxy.gfl.xxx.xxx:8084" settings (all with the same script) Actually now I think on it all it needs to do is toggle the "use proxy" check box off or on.
Thanks

Only the GOOD die young,
Me? I'm here forever!
 
That is not what the logic of your script does. Rather than toggle the way you are saying, why don't you simply use 2 scripts. One for login the other for logout. Set the values using the login script and the first "corrected" version I posted (but switch the 0 to 1) and then as a logout script clear the entry using the second script I posted. That way a user taking a laptop home will always have a cleared proxy setting as long as they logged off of the network.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks Mark, I will give it a try,
I also may see about using an input ie: 1-work 2-home and get the user to select the connection method this way. Thanks again

Only the GOOD die young,
Me? I'm here forever!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top