Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Read Registry Key Without Registry vcx class
Message
De
12/03/2007 12:16:02
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Read Registry Key Without Registry vcx class
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01202744
Message ID:
01202744
Vues:
73
I can read specific values from registry keys using code without using a separate registry.vcx, but I am having problems with this one. It has been sometime since I looked at this code originally (courtesy UT so long ago I don't even have the original author anylonger) so I know I am forgetting something. Here is the hive:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppWare.Project\shell\Open\Command
and the value I need to read is:
Name       Type       Data
(Default)  REG_SZ     c:\Program Files\AAA\AppWare\AppWare.exe %1
(The above is the only item in the Command Folder)
#Define HKEY_CLASSES_ROOT           -2147483648
#Define HKEY_CURRENT_USER           -2147483647
#Define HKEY_LOCAL_MACHINE          -2147483646
#Define HKEY_USERS                  -2147483645

#Define REG_SZ 				1	&& String
#Define REG_BINARY 			3	&& Binary data
#Define REG_DWORD 			4	&& 32bits int

#Define ERROR_SUCCESS		0	&& OK

LOCAL nKey, cSubKey, cValue, cValueRead

*--Here is the hive
nkey = HKEY_LOCAL_MACHINE
cSubKey = "\SOFTWARE\Classes\AppWare.Project\shell\Open\Command\"
cValue = ""																			&& What goes here?

cValueRead = ReadREG_SZ(nKey, cSubKey, cValue)

IF (EMPTY(cValueRead)) THEN
   =MESSAGEBOX("Function Not Successful.")
ELSE
	? cValueRead
   *RETURN 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 Code
.·*´¨)
.·`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"
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform