Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to get value out of registry if know the key
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00700638
Message ID:
00701352
Views:
17
Hi Lisa,
Here is an example that pulls the locations of the windows fonts from the registry:
*Start of Code
#DEFINE HKEY_LOCAL_MACHINE          -2147483646
#Define HKEY_CURRENT_USER           -2147483647


LOCAL nKey, cSubKey, cValue,  cValueRead
*nkey = HKEY_LOCAL_MACHINE
nKey = HKEY_CURRENT_USER
cSubKey = "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
cValue = "Fonts"

cValueRead = ReadREG_SZ(nKey, cSubKey, cValue)
IF (EMPTY(cValueRead)) THEN
   =MESSAGEBOX("Function Not Successful.")
ELSE
   ? cValueRead
   =MESSAGEBOX("Function Successful.")
ENDIF

FUNCTION ReadREG_SZ
* This function reads a REG_SZ value from the registry. If successful,
* it will return the value read. If not successful, it will return an empty string.
   PARAMETERS  nKey, cSubKey, cValue
   * nKey The root key to open. It can be any of the constants defined below.
   *  #DEFINE HKEY_CLASSES_ROOT           -2147483648
   *  #DEFINE HKEY_CURRENT_USER           -2147483647
   *  #DEFINE HKEY_LOCAL_MACHINE          -2147483646
   *  #DEFINE HKEY_USERS                  -2147483645
   * cSubKey The SubKey to open.
   * cValue The value that is going to be read.

   * Constants that are needed for Registry functions
   #DEFINE REG_SZ   1

   * WIN 32 API functions that are used
   DECLARE Integer RegOpenKey IN Win32API ;
      Integer nHKey, String @cSubKey, Integer @nResult
   DECLARE Integer RegQueryValueEx IN Win32API ;
      Integer nHKey, String lpszValueName, Integer dwReserved,;
      Integer @lpdwType, String @lpbData, Integer @lpcbData
   DECLARE Integer RegCloseKey IN Win32API Integer nHKey

   * Local variables used
   LOCAL nErrCode      && Error Code returned from Registry functions
   LOCAL nKeyHandle    && Handle to Key that is opened in the Registry
   LOCAL lpdwValueType && Type of Value that we are looking for
   LOCAL lpbValue      && The data stored in the value
   LOCAL lpcbValueSize && Size of the variable
   LOCAL lpdwReserved  && Reserved Must be 0
    
   * Initialize the variables
   nKeyHandle = 0
   lpdwReserved = 0           
   lpdwValueType = REG_SZ
   lpbValue = ""
   
   nErrCode = RegOpenKey(nKey, cSubKey, @nKeyHandle)
   * If the error code isn't 0, then the key doesn't exist or can't be opened.
   IF (nErrCode # 0) THEN
      RETURN ""
   ENDIF

   lpcbValueSize = 1 
   * Get the size of the data in the value
   nErrCode=RegQueryValueEx(nKeyHandle, cValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)

   * Make the buffer big enough
   lpbValue = SPACE(lpcbValueSize)   
   nErrCode=RegQueryValueEx(nKeyHandle, cValue, lpdwReserved, @lpdwValueType, @lpbValue, @lpcbValueSize)
   
   =RegCloseKey(nKeyHandle)
   IF (nErrCode # 0) THEN
      RETURN ""
   ENDIF

   lpbValue = LEFT(lpbValue, lpcbValueSize - 1)
RETURN lpbValue
* End of Cod
>Alejandro
>Could you tell me how to get a value out of the rgistry. Specifically I want to read a registry key (I wil know the Key) and determine if the environment is running a Citrix server.
>Thanks
>Carolyn Hamrick
>CSI, Inc
>Easley, Sc
>chamrick@csi-plus.com
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform