我的目的是创建一个.bat 文件,切换“Internet 设置”中的“使用自动配置脚本”复选框。
以下是我的脚本
@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
)
我得到的代理启用部分的输出是
Value Name = AutoConfigURL
Value Type = REG_SZ
**Value Value =yyyy**
Hai
The operation completed successfully.
Proxy Disabled
但是代理启用部分不能正常工作,我得到的输出是:
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
答案1
修改以下行:
IF NOT %ValueValue%==yyyy (
到
IF NOT "%ValueValue%"=="yyyy" (
这会让它在没有任何事发生时工作%ValueValue%
。