Skip to content

Latest commit

 

History

History
96 lines (70 loc) · 2.8 KB

RegOpenKeyEx.md

File metadata and controls

96 lines (70 loc) · 2.8 KB

Home

Function name : RegOpenKeyEx

Group: Registry - Library: advapi32


The RegOpenKeyEx function opens the specified registry key.


Code examples:

Reading VFP settings from the Windows Registry
How to save registry key including its subkeys and values to a file
Obtaining current Internet Explorer browser version and UserAgent
Saving local machine ODBC Registry Entries to XML file
How to obtain Content-Type value for a file type from the System Registry
Class library providing access to the System Registry

Declaration:

LONG RegOpenKeyEx(
  HKEY hKey,         // handle to open key
  LPCTSTR lpSubKey,  // subkey name
  DWORD ulOptions,   // reserved
  REGSAM samDesired, // security access mask
  PHKEY phkResult    // handle to open key
);  

FoxPro declaration:

DECLARE INTEGER RegOpenKeyEx IN advapi32;
	INTEGER   hKey,;
	STRING    lpSubKey,;
	INTEGER   ulOptions,;
	INTEGER   samDesired,;
	INTEGER @ phkResult  

Parameters:

hKey [in] Handle to a currently open key or a predefined reserved handle value.

lpSubKey [in] Pointer to a null-terminated string containing the name of the subkey to open.

ulOptions Reserved; must be zero.

samDesired [in] An access mask that specifies the desired access rights to the key.

phkResult [out] Pointer to a variable that receives a handle to the opened key.


Return value:

If the function succeeds, the return value is 0 (ERROR_SUCCESS). Otherwise, the return value is a nonzero error code.


Comments:

When you no longer need the handle returned by this function, call the RegCloseKey function to close it.


June 2, 2010. Contributed by Igor Nikiforov:

Under Windows 2008 Server 64-bit, a call to RegOpenKeyEx returns error code 2 (ERROR_FILE_NOT_FOUND) for some keys.

Example:

RegOpenKeyEx(HKEY_LOCAL_MACHINE ,;   
	[SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\ ... ;  
	... \InstallProperties], 0, ;  
	KEY_READ, @hKey)

Changing samDesired input parameter from KEY_READ to ( KEY_READ | KEY_WOW64_64KEY ) resolves the issue.

RegOpenKeyEx(HKEY_LOCAL_MACHINE , ;  
	[SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\ ... ;  
	... \InstallProperties], 0, ;  
	BITOR(KEY_READ, KEY_WOW64_64KEY), @hKey)

Find more in Registry Key Security and Access Rights article on MSDN web site.