|Here ya go:|
SET my_key=HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security\Trusted Locations
FOR /F "delims=" %%a IN ('REG QUERY "%my_key%" /s^|FIND /I "%my_key%"') DO (
SET /A last_char=4
ECHO !last_num!|FINDSTR /B /R "[0-9]" >NUL
IF !ERRORLEVEL! GTR 0 (
SET /A last_char-=1
IF !last_char! EQU 0 (
SET /A last_num=0
SET /A next_num=%last_num%+1
REM REG ADD %next_key%
REM REG ADD %next_key% /v "Value Name" /t REG_SV /d "New Value"
The first FOR /F loops through all the keys that look like my_key,
and sets the variable named last_key to it's value. If another key
is found, last_key is replaced with that key's name. Repeats until
it finds no more.
The next part grabs the last for characters of the last key's name,
then tests it using FINDSTR's regex capabilities to see if the first
character is a number. If it's not, the number of characters checked
is shrunk by 1, and tested again. This is repeated until a number is
found, or the number of characters to check becomes zero. If the
number of characters to check is zero, the last number will be implied
Now that we have a known numbered key, some math is performed
to increment that number by one, which will become a part of the
next key's name. The next key's name is derived from the last key's
name, but shortened at the end by the number of characters that were
numbers, then concatenated with the number that just had math
performed on it.
At this point, the "%next_key% is ready to be added into the registry
with whatever values you need to add. Simple, huh?
Insomniac at large