Algorithms
Electronics
File Formats
Games Programming
Hardware/Architecture
Humour
Java/Javascript
Link Site,Library
Linux,GNU
Magazines/Books
Networks
New/Latest Stuff
Programming Languages
Protocols
Servers/ISAPI/ IO Completion Ports
Sound and Music
Source Code
Visual Basic
Windows
Winsock

Detecting Whether a Windows 95/98 Component is installed

The Sample Code below shows a program that demonstrates how to detect an Optional Component (in this case Remote Network Accesss) of Windows 95/98. It opens the Registry to where windows stores what items are installed.

This that then be used to determine wether that component needs to be installed or not. To find out what szComponent needs to be, just look in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\OptionalComponents\
which should give you clues to what you can check for.

Sample Program

include <windows.h>
include <stdio.h>

char *szRegPathOptional 	= "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\OptionalComponents\\";
/////////////////////////////////////////////////////////////////////////////
// DetectOptionalComponent
//

RETERR DetectOptionalComponent( BOOL* bRetF, const char* szComponent )
{
HKEY  hKey;
DWORD err;
char  szRegPath[ REGSTR_MAX_VALUE_LENGTH];

lstrcpy( szRegPath, szRegPathOptional );
lstrcat( szRegPath, szComponent );

*bRetF = FALSE;
err   = RegOpenKey( HKEY_LOCAL_MACHINE, szRegPath, &hKey );

if ( (err == ERROR_SUCCESS) && hKey )
  {
   char  szKeyValue[ REGSTR_MAX_VALUE_LENGTH + 1 ] = "";
   DWORD dwSize = sizeof( szKeyValue );

   err = SURegQueryValueEx( hKey, "Installed", NULL, NULL, (LPSTR)szKeyValue, &dwSize );

   RegCloseKey( hKey );

   if ( lstrcmpi( szKeyValue, "0" ) )
     {
     // szKeyValue is something other that "0" so rna is installed!
     *bRetF = TRUE;
     }
  }

// If you can't open the key then it needs to be installed.
return err;
}

int main()
{
DWORD err;
BOOL bRetRNA;
err = DetectOptionalComponent(&bRetRNA,"RNA");
if(err == 0 && bRetRNA==TRUE)
  printf("RNA is installed\n");
else
  printf("RNA is not installed\n");
return 0;
}

Copyright Geoffrey Smith 2000