Avatar of Fady AbuZuaiter
Fady AbuZuaiterFlag 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
Avatar of Fady AbuZuaiter
Fady AbuZuaiter
Flag of Qatar image

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

Avatar of arnold
arnold
Flag of United States of America image

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.
Avatar of 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,
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Craig Beck
Craig Beck
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft Legacy OS
Microsoft Legacy OS

The Microsoft Legacy Operating System topic includes legacy versions of Microsoft operating systems prior to Windows 2000: All versions of MS-DOS and other versions developed for specific manufacturers and Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions, and Windows Mobile.

55K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo