Batch File: If registry key's data is equal to

前端 未结 2 1598
野性不改
野性不改 2021-01-03 11:44

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 ex

相关标签:
2条回答
  • 2021-01-03 12:02

    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
    
    0 讨论(0)
  • 2021-01-03 12:09

    The /d switch doesn't do what you think. It is a modifier to the /f switch, which is used to specify a search pattern. Unfortunately, /v already defines a search pattern, and they do not get along.

    To check whether HideFileExt is set to 0, you can pipe reg's result to find:

    reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt | find "0x0"
    if errorlevel 1 echo "HideFileExt is 0"
    if errorlevel 0 echo "HideFileExt is not 0"
    
    0 讨论(0)
提交回复
热议问题