批处理文件:如果注册表项的数据等于 [英] Batch File: If registry key's data is equal to

查看:57
本文介绍了批处理文件:如果注册表项的数据等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为某些资源管理器设置制作一个.bat切换器.为此,我需要批处理文件来查询注册表项的数据,然后相应地设置项.例如,在ActionScript 3或JavaScript中,可能类似于以下内容:

I'm trying to make a .bat toggler for certain Explorer settings. To do this I need the batch file to query the Registry key's data and then set the key accordingly. For example, in ActionScript 3 or JavaScript it would be something along the lines of this:

if (HideFileExt == "00000000"){
    HideFileExt = 00000001;
else {
    HideFileExt = 00000000;
}

这样,每次运行它都会将密钥的数据设置为与当前相反的数据-切换器.

This way, every time it runs it will set the key's data to be the opposite of what it currently is - a toggler.

我已经广泛使用Google-d,经过很长时间的整理和拼接多个示例之后,我终于明白了:

I have Google-d this extensively and after quite a long time of chopping up and splicing multiple examples, I eventually got this:

REG QUERY HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 00000000

if errorlevel 1 (
    echo Num 1
) else (
    echo Num 2
)

rem The "echo Num"s are there just so that I could eventually figure out what the errorlevel does

返回错误:

ERROR: Invalid syntax.
Type "REG QUERY /? for usage.
num 1

如果我从REG QUERY中删除了/d 00000000,那么它将返回键的准确数据值而不会出现错误.我也用/d 0/d 0x0/d 0x00000000尝试过,但它们也不起作用.

If I remove the /d 00000000 from the REG QUERY then it returns the accurate data value of the key without error. I have also tried it with /d 0, /d 0x0 and /d 0x00000000 and they didn't work either.

推荐答案

丹尼斯(Dennis)的回答是正确的,但我认为id会粘贴整个批处理文件,以便您可以看到它们全部正常工作.

The Answer from Dennis is correct, but I thought id paste the whole batch file so you can see it all working.

REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v "HideFileExt" | Find "0x0"
IF %ERRORLEVEL% == 1 goto turnoff
If %ERRORLEVEL% == 0 goto turnon

goto end
:turnon
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v 

HideFileExt /t REG_DWORD /f /D 1
goto end

:turnoff
REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v 

HideFileExt /t REG_DWORD /f /D 0
goto end

:end
@exit

这篇关于批处理文件:如果注册表项的数据等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆