Nunos Posted December 8, 2012 Share Posted December 8, 2012 I am trying to make a script to change the proxy on a few pc's throughout our organization that will need to point to a specific proxy server and port. The script below seems close but I am struggling with a few things first it doesn't actually seem to change the values. It runs as if everything is fine but then when I check the settings to verify them it is not enabled. The second issue is when you do click Enable it prompts you to enter the ip, which I have set to 127.0.0.0 for testing, but clicking cancel does nothing. I would like it to just close and not try to set anything in case someone makes a mistake. expandcollapse popup#RequireAdmin Dim $sTitle = "IE Proxy is:" Dim $Proxy = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings","ProxyEnable") ;MsgBox(0,"",$Proxy) If $Proxy = 0 Then MsgBox(8228,$sTitle, @TAB & " Disabled" & @CRLF & " Would you like to Enable it now?") $ProxyIP = 0 While Not $ProxyIP Select case $ProxyIP = 0 $ProxyIP = InputBox("Proxy IP", "Type in the desired proxy address.","127.0.0.1") EndSelect WEnd $sProxy = RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "Proxyenable", "REG_DWORD", "1") RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "proxyserver", "REG_SZ",$ProxyIP) RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "proxyoverride", "REG_SZ", "*.local;<local>") ElseIf $Proxy = 1 Then MsgBox(8228,$sTitle, @TAB & " Enabled" & @CRLF & " Would you like to Disable it now?") RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings", "Proxyenable", "REG_DWORD", "0") EndIf Link to comment Share on other sites More sharing options...
BrewManNH Posted December 8, 2012 Share Posted December 8, 2012 You can't use #RequireAdmin and write to the HKCU key, because RequireAdmin will write to the Admin's HKCU key, and not the currently logged in user's key. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Nunos Posted December 8, 2012 Author Share Posted December 8, 2012 (edited) OK that makes sense to me. I will give that a go thank you BrewManNH. If I make this a part of a larger script that already calls #RequireAdmin is there a way I could make this one run with out the elevation? OK here are the changes. I added @error to the inputbox is that the proper use of it? Also I am curious if I can run this as part of a larger script that already executes with #RequireAdmin. Thank you for your time helping me and sorry if these are totally noob questions I am trying to learn as I go. Dim $sTitle = "IE Proxy is:" Dim $Proxy = RegRead("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings","ProxyEnable") ;MsgBox(0,"",$Proxy) If $Proxy = 0 Then MsgBox(8228,$sTitle, @TAB & " Disabled" & @CRLF & " Would you like to Enable it now?") $ProxyIP = 0 While Not $ProxyIP Select case $ProxyIP = 0 $ProxyIP = InputBox("Proxy IP", "Type in the desired proxy address.","127.0.0.1") If @error = 1 Then Exit EndIf EndSelect WEnd $sProxy = RegWrite("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings", "Proxyenable", "REG_DWORD", "1") RegWrite("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings", "proxyserver", "REG_SZ",$ProxyIP) RegWrite("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings", "proxyoverride", "REG_SZ", "*.local;") ElseIf $Proxy = 1 Then MsgBox(8228,$sTitle, @TAB & " Enabled" & @CRLF & " Would you like to Disable it now?") RegWrite("HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings", "Proxyenable", "REG_DWORD", "0") EndIf Edited December 8, 2012 by Nunos Link to comment Share on other sites More sharing options...
Chance Posted December 8, 2012 Share Posted December 8, 2012 Try not to use admin privileges in basic scripts if a lot of people will use it, it's a bad move. I have this code that I use that's part of a project, over 100-200 people have tested it and it seems to work only with Google Chrome, Chromium, Safari and IE, Opera and FireFox need to be restarted to have the changes effect their settings. This will set the proxy for said browsers for current user. If you're running the script in admin mode, I don't know, I haven't dealt with that yet. In my machine, I'm on an admin account, so running as admin makes no difference. expandcollapse popupGlobal $ProxyOverRide = "<LOCAL>" _SetProxyData(0) ;_SetProxyData('190.249.161.243:8081') Func _SetProxyData($Proxy = 0); call with no parameter to remove the proxy Local $reg, $reg1, $key = "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet Settings" If @OSArch <> "X86" Then $key = "HKEY_CURRENT_USER64SoftwareMicrosoftWindowsCurrentVersionInternet Settings" Local $Temp If Not $Proxy Then $reg = RegWrite($key, "ProxyEnable", "REG_DWORD", "0") $reg1 = RegWrite($key, "ProxyServer", "REG_SZ", "") RegWrite($key, "ProxyOverride", "REG_SZ", "") ;~ _GUICtrlStatusBar_SetText($StatusBar, "Status: Naked on the internet.", 0) ;~ _ConsoleWrite("You are not using a proxy!" & @CR, Random(12, 19, 1), 0xFFCC00); random color stuff ;~ GUICtrlSetBkColor($hCurrentUsedProxyEntry, 0xFFFFFF); remove highlight if any Else ;~ If Not $IsInOperation Then ;~ _Proxy_ISP_Check() ;~ EndIf $reg = RegWrite($key, "ProxyEnable", "REG_DWORD", "1") $reg1 = RegWrite($key, "ProxyServer", "REG_SZ", $Proxy) RegWrite($key, "ProxyOverride", "REG_SZ", $ProxyOverRide) ;~ _GUICtrlStatusBar_SetText($StatusBar1, "Currently Using: " & $Proxy, 0) ;~ $Temp = DllCall($hMSVCRT, "int:cdecl", "time", "int", 0) ;~ _SQLite_Exec($hProxyDataBase, "UPDATE topnotch SET bumped='" & $Temp[0] & "' WHERE proxy='" & $Proxy & "';") $Proxy_Used = 1 ;~ _ConsoleWrite("Currently using: ", 11) ;~ _ConsoleWrite($Proxy & @CR, 12, 0xFFCC00) EndIf If Not ($reg And $reg1) Then MsgBox(16, "Error!", "Something went wrong while trying to set the proxy, maybe permissions.") #define INTERNET_OPTION_SETTINGS_CHANGED 39 DllCall('WININET.DLL', 'long', 'InternetSetOption', 'int', 0, 'long', 39, 'str', 0, 'long', 0) Return EndFunc ;==>_SetProxyData Link to comment Share on other sites More sharing options...
Nunos Posted December 8, 2012 Author Share Posted December 8, 2012 The script is run by three people and is required to complete the tasks that the script is doing. If it is not possible to run just this portion of the script without admin privelages then I will just exclude it from the script and make it into its own little script but it would be nice if it would do the UAC prompt for the portions that need it and not this one little thing. Here we don't run any computer with admin privelages even the IT guys use regualr accounts and just use admin privelages to do the work they need to. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now