(view source code of checkregaccess.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
IF "%~2"=="" GOTO Syntax
IF NOT "%~3"=="" GOTO Syntax
WMIC /? >NUL 2>&1 || GOTO Syntax
ECHO.%* | FINDSTR /R /C:"[/?]" >NUL && GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
SET hDefKey=
SET sSubKeyName=
SET uRequired=
:: permission name number description
:: =============== ====== ===========
:: KEY_QUERY_VALUE 0x1 query the values of a registry key
:: KEY_SET_VALUE 0x2 create, delete, or set a registry value
:: KEY_CREATE_SUB_KEY 0x4 create a subkey of a registry key
:: KEY_ENUMERATE_SUB_KEYS 0x8 enumerate the subkeys of a registry key
:: KEY_NOTIFY 0x10 request change notifications for a registry key or for subkeys of a registry key
:: KEY_CREATE 0x20 create a registry key
:: DELETE 0x10000 delete a registry key
:: READ_CONTROL 0x20000 Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values
:: WRITE_DAC 0x40000 modify the DACL in the object's security descriptor
:: WRITE_OWNER 0x80000 change the owner in the object's security descriptor
SET KEY_QUERY_VALUE="&H1"
SET KEY_SET_VALUE="&H2"
SET KEY_CREATE_SUB_KEY="&H4"
SET KEY_ENUMERATE_SUB_KEYS="&H8"
SET KEY_NOTIFY="&H10"
SET KEY_CREATE="&H20"
SET DELETE="&H10000"
SET READ_CONTROL="&H20000"
SET WRITE_DAC="&H40000"
SET WRITE_OWNER="&H80000"
IF DEFINED %~2 (
SET uRequired=!%~2!
) ELSE (
SET uRequired=%~2
SET uRequired="!uRequired:0x=&H!"
)
FOR /F "tokens=1* delims=\" %%A IN ("%~1") DO (
IF "%%~A"=="HKEY_CLASSES_ROOT" SET hDefKey="&H80000000"
IF "%%~A"=="HKCR" SET hDefKey="&H80000000"
IF "%%~A"=="HKEY_CURRENT_USER" SET hDefKey="&H80000001"
IF "%%~A"=="HKCU" SET hDefKey="&H80000001"
IF "%%~A"=="HKEY_LOCAL_MACHINE" SET hDefKey="&H80000002"
IF "%%~A"=="HKLM" SET hDefKey="&H80000002"
IF "%%~A"=="HKEY_USERS" SET hDefKey="&H80000003"
IF "%%~A"=="HKU" SET hDefKey="&H80000003"
IF "%%~A"=="HKEY_CURRENT_CONFIG" SET hDefKey="&H80000005"
IF "%%~A"=="HKCC" SET hDefKey="&H80000005"
IF NOT "%%~B"=="" SET sSubKeyName="%%~B"
)
IF DEFINED hDefKey IF DEFINED sSubKeyName IF DEFINED uRequired (
IF DEFINED Debug (
ECHO WMIC /NameSpace:\\root\default Class StdRegProv Call CheckAccess hDefKey=%hDefKey% sSubKeyName=%sSubKeyName% uRequired=%uRequired%
)
WMIC /NameSpace:\\root\default Class StdRegProv Call CheckAccess hDefKey=%hDefKey% sSubKeyName=%sSubKeyName% uRequired=%uRequired%
) ELSE (
ENDLOCAL
GOTO Syntax
)
ENDLOCAL
GOTO:EOF
:Syntax
ECHO.
ECHO CheckRegAccess.bat, Version 1.00 for Windows XP Professional and later
ECHO Check if you have access to the specified registry key
ECHO
ECHO Usage: %~n0 "HIVE\RegKeyPath" permission
ECHO.
ECHO Where: HIVE is the registry hive name, e.g. HKEY_USERS or HKU
ECHO RegKeyPath is the registry key path to be queried for access
ECHO permission is the requested acces permission (name or hexadecimal)
ECHO.
ECHO Return codes: 0 for true (access), 1 for syntax error, 2 for false (no access)
ECHO.
ECHO Examples:
ECHO Check write acces:
ECHO %~n0 "HKLM\Software\My Software" KEY_SET_VALUE
ECHO %~n0 "HKLM\Software\My Software" 0x2
ECHO Check read control access:
ECHO %~n0 "HKLM\Software\My Software" READ_CONTROL
ECHO %~n0 "HKLM\Software\My Software" 0x20000
ECHO.
ECHO Note: For more details on permission values, check this script's comments or
ECHO http://msdn.microsoft.com/en-us/library/aa384911^(v=VS.85^).aspx
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0092 seconds