Home > front end >  check ProxyEnable in a batch file
check ProxyEnable in a batch file

Time:05-16

I currently have two batch files: proxy_enable.bat

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
    /v ProxyEnable /t REG_DWORD /d 1 /f

and proxy_disable.bat

reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^
    /v ProxyEnable /t REG_DWORD /d 0 /f

I would like to make only one file which would be proxy_switch.bat and that would be:

if (registry key is 0) (put it to 1) ELSE (put it to 0)

But I can't find a way to read the ProxyEnable key that is in HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings

CodePudding user response:

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable" | find /i "0x0" && goto :set1
:set0
set it here to 0
goto :end
:set1
set it here to 1
:end

CodePudding user response:

The following script should toggle the value, each time it is run:

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "Fnd=%SystemRoot%\System32\find.exe"
Set "Reg=%SystemRoot%\System32\reg.exe"
Set "Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Set "Val=ProxyEnable"
Set "Typ=REG_DWORD"

%Reg% Query "%Key%" /V "%Val%" | %Fnd% "x0" 1>NUL && (
    %Reg% Add "%Key%" /V "%Val%" /T %Typ% /D "1" /F 1>NUL
) || %Reg% Add "%Key%" /V "%Val%" /T %Typ% /D "0" /F 1>NUL

  • Related