Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / VALUE function accessing registry

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. VALUE function accessing registry
#1825
Posted by: 2003-06-03 07:14:28
I am trying to use Reginald's VALUE function to retrieve a value named "DosDevicesC:" from the registry key HKEY_LOCAL_MACHINESYSTEMMOUNTEDDEVICES.

It seems the VALUE function strips off the leading  from the value name, preventing retrieving or setting of values that start with a backslash.

Is there any "escape" sequence that would permit literally specifying a value that starts with a backslash?
Message2. Re: VALUE function accessing registry
#1826
Posted by: Jeff Glatt 2003-06-03 10:41:21
I wasn't even aware that registry key names could have embedded backslashes in them. I assumed that would be a reserved character, so I didn't design VALUE() to handle them.

You have two options. You can wait for me to issue a Reginald update to alter the VALUE function to accomodate this. Or, you can use the generic call interface (ie, FUNCDEF) to register and call the OS function RegQueryValueEx() on your own, which is actually fairly easy:
/* Make things easy for us with WINFUNC option */
OPTIONS "WINFUNC"

/* Register RegOpenKeyEx once */
err = FUNCDEF("RegOpenKeyEx", "32, void, str, 32u, 32u, void stor", 'advapi32')
IF err == 0 THEN DO
   SAY "Failed to register RegOpenKeyEx:" err
   RETURN
END

/* Register RegCloseKey */
err = FUNCDEF("RegCloseKey", "32, void", 'advapi32')
IF err == 0 THEN DO
   SAY "Failed to register RegCloseKey:" err
   RETURN
END

/* Done with initialization */
/* =======================================================
 * Querying a binary value
 * =======================================================
 */

/* Register RegQueryValueEx once, so we can call it
 * as many times as we like. We'll define it once callable
 * as RegQueryBinary to query a binary value. Note: We set
 * the char stor to hold 260 bytes. You should make it as
 * large as the largest binary value you expect to read from
 *  the registry
 */
err = FUNCDEF("RegQueryBinary", "32, void, str, void, 32 *, char[260] stor, 32 * dual", 'advapi32', 'RegQueryValueEx')
IF err == 0 THEN DO
   SAY "Failed to register RegQueryBinary:" err
   RETURN
END

/* The first arg to RegopenKeyEx is either the return from
 * RegOpenKeyEx() for the parent key, or one of the following
 * literal strings:
 *
 * "2147483648" for HKEY_CLASSES_ROOT
 * "2147483649" for HKEY_CURRENT_USER
 * "2147483650" for HKEY_LOCAL_MACHINE
 * "2147483651" for HKEY_USERS
 * "2147483652" for HKEY_PERFORMANCE_DATA
 * "2147483653" for HKEY_CURRENT_CONFIG
 * "2147483654" for HKEY_DYN_DATA
 *
 * Second arg is the name of the key to open.
 *
 * Third arg can be omitted.
 *
 * Fourth arg is one of the following:
 *
 * 983103 = all types of access/notification.
 * 131097 = read a value, and enumerate keys, or be notified when a key/value changes.
 * 131078 = write a value or create a key.
 * 1 = read a value only.
 * 2 = write a value only.
 * 4 = create a key only.
 * 8 = enumerate keys only.
 * 16 = Be notified when a key/value changes.
 * 32= Create a symbolic link only.
 *
 * The fifth arg is the name of the REXX variable where you
 * want the key handle stored.
 *
 * RETURNS: 0 if success, or an error number. If the key doesn't
 * exist, an error is returned.
 */

/* Open the "HKEY_LOCAL_MACHINESYSTEMMountedDevices" key for reading */
err = regopenkeyex("2147483650", "SYSTEMMountedDevices", , "131097", handle) 
IF err == 0 THEN DO

  
/* The first arg to RegQueryValue is the return value from
    * RegOpenKeyEx() for the key that contains this value:
    *
    * Second arg is the value name.
    *
    * Third arg can be omitted.
    *
    * Fourth arg is the name of a REXX variable with one of the following values:
    *
    * 0 = No defined value type
    * 1 = Null terminated string
    * 2 = A null-terminated string that contains unexpanded references to
    *     environment variables (for example, "%PATH%").
    * 3 = Binary data in any form
    * 4 = 32-bit number in Intel format (little endian)
    * 5 = 32-bit number in big endian format
    * 6 = Symbolic Link
    * 7 = An array of null-terminated strings, terminated by two null characters
    * 8 = Resource list in the resource map
    * 9 = Resource list in the hardware description
    * 10 = REG_RESOURCE_REQUIREMENTS_LIST
    *
    * Fifth arg is the name of the variable where you want the value stored.
    *
    * Sixth arg is the name of the variable where you store the max size of the
    * string buffer. We set this to 260 when we FUNCDEF'd RegQueryValueEx.
    * After the function returns successfully, this variable will be set to how
    * long the returned value is (in bytes).
    *
    * If success, 0 is returned, otherwise an error number. If the buffer we
    * specified is too small, we'll get an error, and the above variable will
    * be set to how big a buffer we need.
    */

  
/* Read the binary value "DosDevicesC:" */
   valuetype = 3  /* Binary type */
   myvaluesize = 260
   err = regquerybinary(handle, "DosDevicesC:", , valuetype, myvalue, myvaluesize)
   IF err == 0 THEN SAY "Error reading binary value:" err
   ELSE DO
      SAY "Length of binary data is" myvaluesize "bytes"

     
/* For reading a binary value, we have to trim off only what we need */
      myvalue = LEFT(myvalue, myvaluesize)
   END

  
/* Close the key */
   CALL regclosekey(handle)

END

ELSE SAY "Can't open the key:" err
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-4-25  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0