LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI app : read values in registry key

Hello
I have written an CVI app., which should read values in registry key.

In my register base, the mask i want access is (for example) :

SYSTEM\\CurrentControlSet\\Control\\ProductOptions
« ProductType » = dword :00000028
SYSTEM\\CurrentControlSet\\Control\\Product01
« Data1 » = dword :00000102
SYSTEM\\CurrentControlSet\\Control\\Product02
«Data1» = dword :00000058

the function below shows me how retrieve the type and data for a specified
value name (Product Type) with an open registry key
(CurrentControlSet\\Control\\ProductOptions) . ok but i want to enumerate
differents subkeys of a specify key ???
for the example with the key « CurrentControlSet\\Control » the result will
be :
- ProductOptions
- Product01
- Pro
duct02

But i don't know how to do this.
Thanks for help.

Arnaud (France).




DWORD GetWindowsVariant(void)
{
#define MY_BUFSIZE 32 // Arbitrary initial value.
// Dynamic allocation will be used.
HKEY hKey;
TCHAR szProductType[MY_BUFSIZE];
DWORD dwBufLen = MY_BUFSIZE;
LONG lRet;

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
0,
KEY_QUERY_VALUE,
&hKey) != ERROR_SUCCESS) return RTN_ERROR;

lRet = RegQueryValueEx(hKey,
TEXT("ProductType"),
NULL,
NULL,
(LPBYTE)szProductType,
&dwBufLen);

RegCloseKey(hKey);

....
....maybe use KEY_ENUMERATE_SUB_KEYS in RegOpenKeyEx and use
RegQueryMultiplesValues ??
0 Kudos
Message 1 of 6
(5,334 Views)
Damned, no answer... I'm looking for the same.
0 Kudos
Message 2 of 6
(5,031 Views)
RegQueryInfoOnKey returns the number of values (and the max value name length, so you can allocate an appropriate buffer) that exist for a particular registry key. You can then call RegEnumerateValue once for each value to get the actual names and data.

Mert A.
National Instruments
0 Kudos
Message 3 of 6
(5,021 Views)
That what I thought, but RegEnumerateValue seems to list only values, not subkeys.
I wanna get subkeys under "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\PCI", and RegEnumerateValue doesn't give anything 😞
 
Perhaps there's a mistake in my code. I'm going to take another look.
0 Kudos
Message 4 of 6
(4,999 Views)

I'm probably mistaken but it seems to be impossible to enumerate subkeys with NI toolbox (CVI 7.0).

A good clue : http://msdn2.microsoft.com/en-us/library/ms724256.aspx (but it's not clear, two parameters are IN/OUT !)

Here is a good exemple using SDK with explanation (I hope usefull). I've also attached the file.

#include<windows.h>

void main(void)
{
 int  iStatus = 0;
 
 HKEY  handleKey = NULL;
 
 char  tcSubKeyName[255];            
 int  iSubKeyBufferLen = 255;  // Very important for RegEnumKeyEx calling, you need to give it tcSubKeyName buffer lengh. After you'll get returned lenght
 
 char  tcClass[255];            
 int  iClassBufferLen = 255;
 
 FILETIME fsLastWriteTime;
 
 
 iStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Enum\\PCI", 0, KEY_READ, &handleKey);

 // RegQueryInfoKey() may give interesting information about sunkeys

 if(handleKey != NULL)
 {
  // Reading first one
  iStatus = RegEnumKeyEx(handleKey, 0, tcSubKeyName, &iSubKeyBufferLen, NULL, tcClass, &iClassBufferLen, &fsLastWriteTime);
  // ... should add no error test to detect the end
 
 
  // Reading second one
  iSubKeyBufferLen = 255;
  iClassBufferLen = 255;
  iStatus = RegEnumKeyEx(handleKey, 1, tcSubKeyName, &iSubKeyBufferLen, NULL, tcClass, &iClassBufferLen, &fsLastWriteTime);
  // ... should add no error test to detect the end
  
  
  // Readin...    now you should make a loop 😉
 
  RegCloseKey(handleKey);
  handleKey = NULL;
 }
}

 

0 Kudos
Message 5 of 6
(4,984 Views)
It looks like I misunderstood the question. It appears that you are correct about the CVI Toolbox Registry functions. I'll put in a suggestion to create a RegEnumerateKey function. I'm surprised it isn't already there.

Mert A.
National Instruments
0 Kudos
Message 6 of 6
(4,973 Views)