Read Values of Registry Key

R

Rithesh

Hello,

I am trying to create a setup.dll file. In the "Install_Exit" part of
Setup.dll i am trying to find if .net compact framework is installed
or not. My knowledge of evc++ is minimal. I understand from what i
read, that i should use RegOpenKeyEx :

RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\
\.NETCompactFramework"),0,0,&key)

After i open this how do i read the values of this key. I will need
the values to know which version of .NET CF is installed on the
system. I read some where that it would be 2.0.0.0 for .NET CF 2.0,
but when i checked that value on my PPC using remote registry editor,
that value was 2.0.5238.00.

So my question is, is there any way with which i can read these values
programmatically. And i guess i can assume that if any of these values
starts with "2.0", then .Net CF is installed.


Also it would be great if some one could point me to some link where i
can open a web link programmatically from this setup.dll in IE. In
this link i intend to place the .NET CF binaries for the user to
download.

Thanks in advance and Regards,
Rithesh
 
G

Guest

Here is some sample code that let's you read the values

void ReadCFVersion
{
TCHAR tzValueName[MAX_PATH];
BYTE tzValue[MAX_PATH];
DWORD dwValueSize, dwValueNameSize, dwType;
DWORD dwIndex = 0;
BOOL returnValue = TRUE;
HKEY hKEY;

long l = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\.NETCompactFramework"), 0, 0, &hKEY);

if (l != ERROR_SUCCESS)
{
return TRUE;
}
else
{
memset(tzValueName, 0, MAX_PATH * sizeof(TCHAR));
memset(tzValue, 0, MAX_PATH);
dwValueSize = MAX_PATH;
dwValueNameSize = MAX_PATH;

while(RegEnumValue(hKEY, dwIndex, tzValueName, &dwValueNameSize,
NULL, &dwType, tzValue, &dwValueSize) == ERROR_SUCCESS)
{
// Do something with the tzValueName you could check
tzValue[0] to see if it is 2 for CF Version 2. The cf version is located in
the key name

dwIndex++;
}

RegCloseKey(hKEY);
return returnValue;
}
}
else
{
return FALSE;
}
}

Rick D.
Contractor
 
G

Guest

Here's a C# version

private void GetCFVersion()
{
Microsoft.Win32.RegistryKey key = null;
string[] subKeyNames;

try
{
key =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\.NETCompactFramework");

subKeyNames = key.GetValueNames();

// Do something with the key names in subKeyNames. The cf
versions exist here
}
catch(Exception ex)
{
// Do something with the error
}
finally
{
if (key != null)
{
key.Close();
}
}
}

Rick D.
Contractor

dbgrick said:
Here is some sample code that let's you read the values

void ReadCFVersion
{
TCHAR tzValueName[MAX_PATH];
BYTE tzValue[MAX_PATH];
DWORD dwValueSize, dwValueNameSize, dwType;
DWORD dwIndex = 0;
BOOL returnValue = TRUE;
HKEY hKEY;

long l = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\.NETCompactFramework"), 0, 0, &hKEY);

if (l != ERROR_SUCCESS)
{
return TRUE;
}
else
{
memset(tzValueName, 0, MAX_PATH * sizeof(TCHAR));
memset(tzValue, 0, MAX_PATH);
dwValueSize = MAX_PATH;
dwValueNameSize = MAX_PATH;

while(RegEnumValue(hKEY, dwIndex, tzValueName, &dwValueNameSize,
NULL, &dwType, tzValue, &dwValueSize) == ERROR_SUCCESS)
{
// Do something with the tzValueName you could check
tzValue[0] to see if it is 2 for CF Version 2. The cf version is located in
the key name

dwIndex++;
}

RegCloseKey(hKEY);
return returnValue;
}
}
else
{
return FALSE;
}
}

Rick D.
Contractor

Rithesh said:
Hello,

I am trying to create a setup.dll file. In the "Install_Exit" part of
Setup.dll i am trying to find if .net compact framework is installed
or not. My knowledge of evc++ is minimal. I understand from what i
read, that i should use RegOpenKeyEx :

RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\
\.NETCompactFramework"),0,0,&key)

After i open this how do i read the values of this key. I will need
the values to know which version of .NET CF is installed on the
system. I read some where that it would be 2.0.0.0 for .NET CF 2.0,
but when i checked that value on my PPC using remote registry editor,
that value was 2.0.5238.00.

So my question is, is there any way with which i can read these values
programmatically. And i guess i can assume that if any of these values
starts with "2.0", then .Net CF is installed.


Also it would be great if some one could point me to some link where i
can open a web link programmatically from this setup.dll in IE. In
this link i intend to place the .NET CF binaries for the user to
download.

Thanks in advance and Regards,
Rithesh
 
R

Rithesh

Thanks a lot Rick and Chris. That was exactly what i wanted.

Anyways the answer to the 2nd question i had posted is to use the
CreateProcess method

PROCESS_INFORMATION pi = {0};
LPCTSTR lpExe = _T("iexplore.exe");
LPCTSTR lpCmdLine = _T("The http link");
CreateProcess(lpExe, lpCmdLine, NULL, NULL, FALSE, 0, NULL, NULL,
NULL, &pi);

Thanks a lot again.

Regards,
Rithesh


Here's a C# version

private void GetCFVersion()
{
Microsoft.Win32.RegistryKey key = null;
string[] subKeyNames;

try
{
key =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\.NETCompactFramework");

subKeyNames = key.GetValueNames();

// Do something with the key names in subKeyNames. The cf
versions exist here
}
catch(Exception ex)
{
// Do something with the error
}
finally
{
if (key != null)
{
key.Close();
}
}
}

Rick D.
Contractor

dbgrick said:
Here is some sample code that let's you read the values
void ReadCFVersion
{
TCHAR tzValueName[MAX_PATH];
BYTE tzValue[MAX_PATH];
DWORD dwValueSize, dwValueNameSize, dwType;
DWORD dwIndex = 0;
BOOL returnValue = TRUE;
HKEY hKEY;
long l = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\.NETCompactFramework"), 0, 0, &hKEY);
if (l != ERROR_SUCCESS)
{
return TRUE;
}
else
{
memset(tzValueName, 0, MAX_PATH * sizeof(TCHAR));
memset(tzValue, 0, MAX_PATH);
dwValueSize = MAX_PATH;
dwValueNameSize = MAX_PATH;
while(RegEnumValue(hKEY, dwIndex, tzValueName, &dwValueNameSize,
NULL, &dwType, tzValue, &dwValueSize) == ERROR_SUCCESS)
{
// Do something with the tzValueName you could check
tzValue[0] to see if it is 2 for CF Version 2. The cf version is located in
the key name
dwIndex++;
}

RegCloseKey(hKEY);
return returnValue;
}
}
else
{
return FALSE;
}
}
Rick D.
Contractor
"Rithesh" wrote:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top