RegQueryStr

Retrieves and expands a string value from the registry.

Syntax:

RegQueryStr(handle, subkey-string [,view-flag])

Parameters:

(i) handle an open registration database key (see below).

(s) subkey-string  a path from the key provided to the desired key, including the "data item name" in square brackets at the end of the key string.

(i) view-flag [optional] controls which registry view the function uses when accessing the Windows registry.
0 - view indicated by the last call to the RegOpenFlags.
32 - use the 32-bit registry view.
64 - use the 64-bit registry view.

Returns:

(i) value the expanded registry value

 

This function can be used to read a REG_SZ or REG_EXPAND_SZ value from the registry. If the value is a REG_EXPAND_SZ, any environment strings will be expanded to their defined values in the string returned by this function (the registry entry itself is untouched).

View-flag

This optional parameter controls which registry view the function uses when accessing the Windows registry. The optional parameter's values can be 32 to use the 32-bit view, 64 to use the 64-bit view, or 0 to use the view indicated by the last call to the RegOpenFlags. The parameter value of 0 can also causes a function to use the WinBatch default 64-bit view, if no call to RegOpenFlags has been made and setting the parameter to 0 is equivalent to omitting the parameter entirely.

Notes:

Windows Vista/2008 and newer: This function may require an Administrator level account, if it attempts to access protected registry keys: HKEY_LOCAL_MACHINE  or HKEY_CLASSES_ROOT.

Example:


userenv="Environment[path]"
sysenv="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
If WinVersion(4)!=4
   Message("RegQueryStr","Not supported in Non-NT versions of Windows")
   Exit
EndIf
If WinVersion(1)!=4 ; Win NT 4.0
   Message("RegQueryStr","Script not designed for NT 2000 versions of Windows")
   Exit
EndIf
LastError( )
ErrorMode(@OFF)
oldpath=RegQueryStr(@REGCURRENT, userenv)
ErrorMode(@CANCEL)
If LastError( ) == 1233
   ErrorMode(@OFF)
   oldpath=RegQueryStr(@REGMACHINE, sysenv)
   ErrorMode(@CANCEL)
   If oldpath==0
      Message("Environment Variable - Users Path", "No path found")
   Else
      Message("System Environment Variable - Users Path", oldpath)
   EndIf
Else
   Message("User Environment Variable - Users Path", oldpath)
   Exit
EndIf
Exit
See Also:

RegApp, RegEntryType, RegQueryBin, RegQueryDword, RegQueryEx, RegQueryExpSz, RegQueryItem, RegQueryMulSz, RegQueryStr and the section on Registration Database Operations