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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Proxy with VBscript in Windows Vista

Status
Not open for further replies.

kestrel1

Technical User
Jan 8, 2003
932
GB
I have a VBscript that enables users to turn on/off the proxy server on their laptops, so that the proxy server is turned off for home use. This works without a problem in XP or older, but in Vista it will not always change the settings.
I know that it is down to the UAC in Vista, because if the UAC is turned off, the settings always change.
I thought I had a way around this, by getting the VBscript file to turn off the UAC before the rest of the script runs & then turn the UAC back on afterwards.
I can get the UAC turning off & on, but the settings for the proxy don't always take effect. I have tried making the script sleep for a number of seconds, but this still doesn't help.
If I remove the option for the UAC to turn back on after the proxy has changed, the settings change every time.
I do not want to leave the UAC disabled on these machines. Does anyone know of a way to get around this.
I am not a script writer & have got most of the info off of the Internet. I have learnt a fair bit whilst playing around with this, but some help would be appreciated.
 
Add a digital signature to your script. That will probably fix the issue.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
With the chance of looking really thick, how would I add a digital signature to my VBscript file?
Thanks
 
1) You need a Code Signing Certificate, either from a Certificate Authority in your environment or from a commercial Cert Authority.

2) Ensure that all client systems trust the Certificate Authority that issues the certificate.

3) Use a VBScript (or PrimalScript) to sign your script using your code signing certificate. Example Here.

Note: You have to re-sign the script every time it is updated. Changing the size or content invalidates the previous signature.

Considering requirements for Vista and some applications, having your own Enterprise CA, even if it is a virtual machine, is not a bad idea.

Good Luck!

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
I use a little free program qroxy and just scripted it to copy to the machines. Then run at startup.

Code:
on error resume next
Dim WshShell, WshEnv
Const OverwriteExisting = True

'Configures Variables
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
SysDrive = WshEnv("%SYSTEMDRIVE%")
SysRoot = WshEnv("SYSTEMROOT")


source = "\\server\share$\qroxy\*.*" 
dest = SysDrive & "\Program Files\qroxy\"

If objFSO.FolderExists(dest) Then
  Set objFolder = objFSO.GetFolder(dest)
Else
  Set objFolder = objFSO.CreateFolder(dest)
End If

objFSO.CopyFile  Source  , Dest  , OverwriteExisting = true

WshShell.Regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\qroxy", "C:\Program Files\qroxy\qroxy.exe", "REG_SZ"

'Clears cache
set fso = nothing
set WshShell = nothing
set WshEnv = nothing
wscript.quit
 
Haven't tried. But download and test it.
 
Thanks for the suggestion. Nice little program, but is not reliable in Vista.
Sometimes it will switch the proxy on/off, other times you have to use it a few times before changes take effect.
I may play around with it to see if I can get it to work with the Elevate command from the Elevation power tools in the command line version. Will post back if it works.
 
Tried it with the Elevate command, but no go. Still get the same result. I hate Vista. I think it is trying to be too clever. Not sure I want to go down the road of getting a certificate, as this is only a project I started & the bosses would not pay out for anything.
Any other suggestions welcome.
 
I found a way around this problem. I ditched the VB script & setup a .pac file like this:
function FindProxyForURL(url, host)

{

if (isInNet(myIpAddress(), "192.168.0.0", "255.255.255.0"))

return "PROXY 192.168.0.1:8080";

else

return "DIRECT";

}
Point the auto configuration to this file on the web server & the proxy works when the machine is on the local network & switches off when outside of the network.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top