Registry Issues

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Dec 2, 2008
209
2
Canada
#1
From and elevated TCC, I was tinkering with some of the @REG functions and ran into some issues. This is what my registry for HKCU\Environment looks like at the beginning:

Semaphore1.png
I now run the following from a .BTM file:

@echo off
echo %@REGEXIST[HKCU\Environment\semiphore]
echo %@REGSET[HKCU\Environment\semiphore,REG_SZ,10]
echo %@REGQUERY[HKCU\Environment\semiphore]
echo %@REGQUERY[HKCU_64\Environment\semiphore]
echo %@REGEXIST[HKCU\Environment\semiphore]
echo %@REGEXIST[HKCU_64\Environment\semiphore]
echo %@REGDELKEY[HKCU\Environment\semiphore]
echo %@REGDELKEY[HKCU_64\Environment\semiphore]
echo %@REGQUERY[HKCU\Environment\semiphore]​

the results are as follows:

0
0
10
10
0
0
0
0
10
The following is the state of my registry after running the .BTM file above:

semaphore2.png

So let look at the results:

echo %@REGEXIST[HKCU\Environment\semiphore] returns a 0 that sound right, the key doesn't exist at this point.

echo %@REGSET[HKCU\Environment\semiphore,REG_SZ,10] returns a 0, that means no error, that sounds right too.

echo %@REGQUERY[HKCU\Environment\semiphore] and echo %@REGQUERY[HKCU_64\Environment\semiphore], query the key and query the key using the 64 bit version both return 10, that the correct value.

echo %@REGEXIST[HKCU\Environment\semiphore] and echo %@REGEXIST[HKCU_64\Environment\semiphore] return 0, but the previous REGQUERY call indicate that the key does exist so these call should be returning 1 and not 0.

echo %@REGDELKEY[HKCU\Environment\semiphore] and echo %@REGDELKEY[HKCU_64\Environment\semiphore] are attempts to delete the key, but the 0 returned indicates that these attempts did fail.

echo %@REGQUERY[HKCU\Environment\semiphore], querying the key returns a 10, indicating that the attempt to delete the key did fail.
Is my understanding of how these @REG functions work flawed or is there a problem with @REGEXIST and @REGDELKEY?
 
Last edited:
#4
Ahh, it seems: only Key-Directories are possible, not Keys itself with this syntax ...

Key-DIR:
Code:
echo %@REGEXIST[HKCU\Environment\]
1

Key itself:
Code:
echo %@REGEXIST[HKCU\Environment\TEMP]
0
PS: TC 19.0.24 64-bit on Win 10 Pro
 
Last edited:
#7
@cgunhouse

Maybe you can use the "-1" method for your purpose:

From Help-File 19.0.24 ...
@REGQUERY[HKEY...\subkey\value]: Read a value from the registry. REGQUERY supports keys of type REG_DWORD, REG_QWORD, REG_EXPAND_SZ, REG_SZ, REG_DWORD_LITTLE_ENDIAN , and REG_QWORD_LITTLE_ENDIAN. If the key is of type REG_EXPAND_SZ, the value is returned without further expansion. If the value name does not exist, the function returns -1. If the value name is not supplied, REGQUERY returns the unnamed value for the specified key (the first value with a NULL name). To retrieve an unnamed value, add a trailing \ to the name.
 

rconn

Administrator
Staff member
May 14, 2008
10,163
86
#8
From and elevated TCC, I was tinkering with some of the @REG functions and ran into some issues. This is what my registry for HKCU\Environment looks like at the beginning:

I now run the following from a .BTM file:

@echo off
echo %@REGEXIST[HKCU\Environment\semiphore]
echo %@REGSET[HKCU\Environment\semiphore,REG_SZ,10]
echo %@REGQUERY[HKCU\Environment\semiphore]
echo %@REGQUERY[HKCU_64\Environment\semiphore]
echo %@REGEXIST[HKCU\Environment\semiphore]
echo %@REGEXIST[HKCU_64\Environment\semiphore]
echo %@REGDELKEY[HKCU\Environment\semiphore]
echo %@REGDELKEY[HKCU_64\Environment\semiphore]
echo %@REGQUERY[HKCU\Environment\semiphore]​
You're trying to use registry keys and registry key values as though they are interchangeable (and they are not!).

In order:

@REGEXIST tests for the existence of the key "HKCU\Environment\semiphore" (which doesn't exist), returning 0. WAD.

@REGSET is setting the value "semiphore" for the key "HKCU\Environment", returning 0 for success. WAD.

@REGQUERY queries the value "semiphore" for the key "HKCU\Environment", returning 10. WAD.
(Your second @REGQUERY does exactly the same thing, assuming you're on an x64 system.)

@REGEXIST tests the existence of the key "semiphore" (there is no key named "semiphore"), returning 0. WAD.
(Your second @REGEXIST does exactly the same thing, assuming you're on an x64 system.)

@REGDELKEY tries to delete the nonexistent key "HKCU\Environment\semiphore", returning 0 because it didn't delete anything. WAD.
(Trying to delete a nonexistent key again won't change the result.)

@REGQUERY queries the value "semiphore" for the key "HKCU\Environment", returning 10. WAD.

There is no flaw anywhere here; everything is WAD.