Batch file script for Enable & disable the “use automatic Configuration Script”

batch filescriptwindows

My intention is to create a .bat file that toggles the check box of "use automatic Configuration Script" in Internet Settings.

The following is my script

@echo OFF

setlocal ENABLEEXTENSIONS
set KEY_NAME="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set VALUE_NAME=AutoConfigURL

FOR /F "usebackq skip=1 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
    set ValueName=%%A
    set ValueType=%%B    
    set ValueValue=%%C
)

@echo Value Name = %ValueName%
@echo Value Type = %ValueType%
@echo Value Value = %ValueValue%

IF  NOT %ValueValue%==yyyy (
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "yyyy" /f
echo Proxy Enabled
) else (
echo  Hai
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v AutoConfigURL /t REG_SZ /d "" /f
echo Proxy Disabled
)

The output i'm getting for the Proxy Enabled part is

Value Name = AutoConfigURL
Value Type = REG_SZ
**Value Value =yyyy**
 Hai
The operation completed successfully.
Proxy Disabled

But the Proxy Enable part isn't working fine
the output i get is
:

Value Name = AutoConfigURL
Value Type = REG_SZ
**Value Value =**
( was unexpected at this time.
The variable "Value Value" is not getting set when we try to do the Proxy enable

Best Answer

Change the line that says:

IF  NOT %ValueValue%==yyyy (

to

IF  NOT "%ValueValue%"=="yyyy" (

Which will make it work when %ValueValue% is nothing.

Related Question