;************************************************************************* ; AutoIT Script to set the proxy server settings in registry ; Both in HKEY_CURRENT_USER and HKEY_USERS (SID!!!) ; ; Tonnie van Gennip - 20061110 ; ;************************************************************************* ; Start of script ; ; Get the SID of the currently logged on user ; $WMI = ObjGet("winmgmts://./root/cimv2") $User = $WMI.Get("Win32_UserAccount.Domain='" & @LogonDomain & "'" & ",Name='" & @UserName & "'") $UserSID = $User.SID ; ; Set up the logfile details - If you don't want to log, comment the next lines out or remove them ; If you do, don't forget to also comment out or remove the actual writing-to-the-file part near the end ; $myProxySettingsLogFileName = "ProxySettings.dat" ; Or whatever name you like to set $myProxySettingsLogFilePath = "C:\ProxyLog" ; In this example I specified a local path, a network path would be nicer (write rights needed!) $myProxySettingsLogFile = $myProxySettingsLogFilePath & "\" & $myProxySettingsLogFileName ; ; Counter for checking the need to write to the logfile ; $Counter = 0 ; ; Set up the ProxyOverride and ProxyServer settings that need to be verified, ; and if not correct need to be written to the registry (HKEY_USERS & HKEY_CURRENT_USER) ; $ProxyOverride = "localhost;127.0.0.1" ; Here you put the exclusions where the proxy needs to be bypassed (";" to separate!) $ProxyServer = "proxy.a-company-making-everything.com:8080" ; This variable holds both the server and the port to connect to ; ; Local user's profile ; $CurrentUser_ProxyOverrideSetting = RegRead("HKEY_USERS\" & $UserSID & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride") If $CurrentUser_ProxyOverrideSetting <> $ProxyOverride Then RegWrite("HKEY_USERS\" & $UserSID & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride", "REG_SZ", $ProxyOverride) $Counter = $Counter + 1 EndIf $CurrentUser_ProxyServerSetting = RegRead("HKEY_USERS\" & $UserSID & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") If $CurrentUser_ProxyServerSetting <> $ProxyServer Then RegWrite("HKEY_USERS\" & $UserSID & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $ProxyServer) $Counter = $Counter + 1 EndIf ; ; Hive Key Current User ; $HKCU_ProxyOverrideSetting = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride") If $HKCU_ProxyOverrideSetting <> $ProxyOverride Then RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyOverride", "REG_SZ", $ProxyOverride) $Counter = $Counter + 1 EndIf $HKCU_ProxyServerSetting = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer") If $HKCU_ProxyServerSetting <> $ProxyServer Then RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyServer", "REG_SZ", $ProxyServer) $Counter = $Counter + 1 EndIf ; ; Write to LogFile if there has been at least one write to registry ; Again, If you don't want to log, comment the next lines out or remove them ; If $Counter > 0 Then $myProxySettingsLogFile_OpenForWritingCheck = FileOpen ($myProxySettingsLogFile, 1) ; ; Check if file can be opened for writing OK, if not, break. ; If $myProxySettingsLogFile_OpenForWritingCheck = -1 Then ; Obviuosly can not write to the file, one could set up a loop or something like that. I didn't. I just quit. Exit EndIf ; ; OK, we can write to the file :-) ; Write the Computername and UserName to the file ; (Or whatever else you want to write. AutoIT has very powerful macros) ; FileWrite($myProxySettingsLogFile, @ComputerName) FileWrite($myProxySettingsLogFile, " - ") FileWrite($myProxySettingsLogFile, @UserName & @CRLF) FileClose($myProxySettingsLogFile) ; ; Inform the user - If you don't want the user to be informed, comment it or remove the line ; MsgBox(64,"ACME IT Department","The Internet Explorer proxyserver settings have been changed ", 5) EndIf ; ; End of script