我正在编写一个批处理文件来自动执行一些故障排除步骤。首先,我要确定用户是否在其Internet Explorer浏览器上启用了“保护模式”。如果他们这样做,我想提示他们将其关闭。我正在通过系统注册表来执行此操作。
我确信注册表项是正确的,因为我已将值从0更改为3,并且它的行为符合我的预期,在Internet Explorer中切换了Internet区域的“保护模式”设置。
这是当前代码:
@echo off
Setlocal EnableDelayedExpansion
REM Check protected mode
echo Checking Internet Explorer settings
set "regCmd=reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v 2500"
for /f "usebackq tokens=3* delims= " %%a in (`!regCmd!`) do (
set /a ProtectedMode=%%a
)
if !ProtectedMode! == 0 (
echo Protected mode in Internet Explorer is enabled. It is recommended that protected mode be disabled in Internet Explorer.
echo.
set /P b_disable="Would you like to disable protected mode in Internet Explorer? (y/n)"
)
REM Checking to see that b_disable is set appropriately, it is
echo !b_disable!
REM Update protected mode to turn it off
if !b_disable!=="y" (
echo Protected mode for Internet Explorer disabled.
)
if !b_disable!=="n" (
echo Protected mode for Internet Explorer was NOT disabled.
)
pause
当我确实启用保护模式时,当前输出为:
检查Internet Explorer设置
在Internet Explorer中启用了保护模式。建议在Internet Explorer中禁用保护模式。
您是否要在Internet Explorer(y / n)y中禁用保护模式
ÿ
按任意键继续 。。。
因此,问题在于if语句似乎没有被评估。我需要知道如何有条件地执行操作(如果用户按下y,我计划实现代码以更新同一键的注册表值)。
我从另一个类似的问题中学到SetLocal
并EnableDelayedExpansion
使用了它!variable!
来引用设置变量
这是我的第一个批处理文件,这对我来说是非常新的。当然,简单地告诉用户进入IE并取消选中“启用保护模式”会更容易,但是任务是使它自动化,同时允许用户进行某些控制(因此,是/否提示)。
请注意,您要检查的注册表可能不存在。仅在!ProtectedMode!模式下才需要检查用户输入。== 0
@echo off
setlocal enabledelayedexpansion
for /f "tokens=3" %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v 2500 2^>nul ^| find "REG_DWORD" 2^>nul') do (
set /a ProtectedMode=%%a
)
echo ProtectedMode=!ProtectedMode!
if !ProtectedMode! == 0 (
echo Protected mode in Internet Explorer is enabled. It is recommended that protected mode be disabled in Internet Explorer.
echo.
set /P b_disable="Would you like to disable protected mode in Internet Explorer? (y/n): "
REM Checking to see that b_disable is set appropriately, it is
echo !b_disable!
REM Update protected mode to turn it off
if "!b_disable!"=="y" (
echo Protected mode for Internet Explorer disabled.
)
if "!b_disable!"=="n" (
echo Protected mode for Internet Explorer was NOT disabled.
)
)
pause
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句