Avatar of Fady AbuZuaiter
Fady AbuZuaiter
Flag for Qatar asked on

Switching Proxy On/Off Automatically script every time user switch between networks

Hello,

I found a script to Enable/Disable proxy if the user inside the organization or outside the organization.

The VBS Script

'#==============================================================================
'#==============================================================================
'#  SCRIPT.........:  Enable Disable IE Proxy.vbs
'#  AUTHOR.........:  Stuart Barrett
'#  VERSION........:  1.0
'#  CREATED........:  15/09/10
'#  COPYRIGHT......:  2010
'#  LICENSE........:  Freeware
'#  REQUIREMENTS...:  
'#  DESCRIPTION....:  Enables or disables IE proxy on the local system
'#
'#  NOTES..........:  
'# 
'#  CUSTOMIZE......:  
'#==============================================================================
'#  REVISED BY.....:  
'#  EMAIL..........:  
'#  REVISION DATE..:  
'#  REVISION NOTES.:
'#
'#==============================================================================
'#==============================================================================

Const HKEY_CURRENT_USER = &H80000001
Set objShell = CreateObject("WScript.Shell")
strPC = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

On Error Resume Next

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"
strValueName = "ProxyEnable"

objReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'#==============================================================================
'#	If IE Proxy is currently enabled display message and ask user whether it
'#	should then be disabled
'#==============================================================================
If dwValue = 1 Then
	IEPrompt = MsgBox ("IE Proxy is currently ENABLED on " & strPC & _
	".  Do you want to DISABLE it?", vbQuestion+vbYesNo, "Disable IE Proxy")
	If IEPrompt = vbYes Then
		dwValue = 0
		objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue 
		MsgBox "IE Proxy is now DISABLED on " & strPC & _
		".",vbInformation, "Disable IE Proxy"
		ElseIf IEPrompt = vbNo Then
			MsgBox "IE Proxy is still ENABLED on " & strPC & _
			".",vbInformation, "Disable IE Proxy"
	End If
	'#==============================================================================
	'#	If IE Proxy is currently disabled display message and ask user whether it
	'#	should then be enabled
	'#==============================================================================
	ElseIf dwValue = 0 Then
		IEPrompt = MsgBox ("IE Proxy is currently DISABLED on " & strPC & _
		".  Do you want to ENABLE it?", vbQuestion+vbYesNo, "Enable IE Proxy")
		If IEPrompt = vbYes Then
			dwValue = 1
			objReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
			MsgBox "IE Proxy is now ENABLED on " & strPC & _
			".",vbInformation, "Enable IE Proxy"
			ElseIf IEPrompt = vbNo Then
				MsgBox "IE Proxy is still DISABLED on " & strPC & _
				".",vbInformation, "Enable IE Proxy"
	End If
End If

Open in new window


But i need a solution apply the switching automatically instead of running the script every time user switch between networks.

In ex: if the user use the Organization network Enabling the proxy automatically and if he use another network the proxy must be disabled.


Regards,
Windows NetworkingWireless NetworkingMicrosoft Legacy OS

Avatar of undefined
Last Comment
arnold

8/22/2022 - Mon
Fady AbuZuaiter

ASKER
I found this script which is .pac script

utoconfigure Scripts for Proxy Settings through IE Scripts

but i need it to dtermine if the PC is in the domain "media.tv" to take the proxy if not to connect direct without proxy


function FindProxyForURL(url, host) {
      if (shExpMatch(host, "MEDIA.TV"))
      {
         return "PROXY 10.10.50.20:80";
else
return "DIRECT";
      }

Open in new window

arnold

Why not use GPO or DHCP, Wpad, DNS and browser proxy auto discovery?

Site based GPO or wpad is more difficult given it requires each branch have unique configuration branch.domain.com otherwise, the two sites will reference the same wpad file to auto configure user proxy settings to the same at either site.
Fady AbuZuaiter

ASKER
Hello arnold,

Can you eplain what you main in the prevoiuse post ?? which method is best ? I need to solve the laptops problem that when they connect to the organization use the proxy settings automatically and when they went house or any where let them connct direct to the internet with out proxy

Regards,
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
arnold

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Craig Beck

Using a PAC file is the easiest method.  This allows the script to check your IP address and apply the proxy only if you're on a specific network (for example).

You can customise the PAC file to check for different variables.

You could also try something like NetSwitcher.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.