1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Registry Issues

Discussion in 'Support' started by cgunhouse, Dec 17, 2015.

  1. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    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?
     
    #1 cgunhouse, Dec 17, 2015
    Last edited: Dec 17, 2015
  2. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    And with "HKEY_CURRENT_USER" instead "HKCU"?
     
  3. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    Same results:

    0
    0
    10
    10
    0
    0
    0
    0
    10​
     
  4. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    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
     
    #4 Alpengreis, Dec 17, 2015
    Last edited: Dec 17, 2015
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    @REGEXIST is for keys, not values. "TEMP" is, I suspect, a value.
     
  6. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    Yup, you was faster than I, found out too self, REALLY :-)
    corrected above ...
     
  7. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    @cgunhouse

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

    From Help-File 19.0.24 ...
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,870
    Likes Received:
    83
    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.
     
  9. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    So my understanding of how these @REG functions work is flawed.

    Thanks for the insight.
     

Share This Page