Using wildcard entries to edit registry using a batch file

Viewed 4310

I am trying to create a batch file to edit

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\VID_04B5&PID_0680&MI_00\8&3AFFB273&0&0000\Device Parameters\SensorPermissions
S-1-1-0 

I would like to set it from 00000000 to 00000001

I am setting this up for multiple machines as part of a ghost image however 8&3AFFB273&0&0000 is a different reg entry on each individual machine, is there any way I can put a wild card in to bypass this section?

Here is my .reg file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\VID_04B5&PID_0680&MI_00\8&3AFFB273&0&0000\Device Parameters\SensorPermissions]
"S-1-1-0"=dword:00000001

This is my batch file

echo off
regedit /s 'c:\users\user\desktop\regfile.reg' 
shutdown /r /t 60
1 Answers

Try this:

@echo off
setlocal

set key=HKLM\SYSTEM\CurrentControlSet\Enum\HID\VID_04B5^&PID_0680^&MI_00
for /f %%a in ('reg query "%key%"') do (
   reg add "%key%\%%~na\Device Parameters\SensorPermissions" /t REG_DWORD /v S-1-1-0 /d 0x1
)

It should prompt saying value S-1-1-0 exists, overwrite. Answer Y. If it says the operation completed successfully, refresh the registry and the value should be changed to 1 now on that key. If it works, you can add a /f switch to force changing without the prompt. I only tested this where there was a single key. If there are more than one keys under VID_04B5&PID_0680&MI_00 or if it's say the 2nd out of 4, this script will have to be adapted.

Related