RAS Detection Routine | CodeGuru

RAS Detection Routine

Environment: VC6 SP3, NT4 SP5 The first thing you should do before you attempt to use a RAS function, is find out it the RAS is actually installed. According to the Microsoft Knowledgebase (article Q181518) can detect wether the RAS has been installed by trying to LoadLibrary(“rasapi32.dll”). I have noticed that on almost all 9x […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 17, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC6 SP3, NT4 SP5

The first thing you should do before you attempt to use a RAS function, is
find out it the RAS is actually installed. According to the
Microsoft Knowledgebase (article Q181518)
can detect wether the RAS has been
installed by trying to LoadLibrary("rasapi32.dll").
I have noticed that on almost all 9x systems (if not all) this will not work.
If you have installed the RAS and later removed it, the rasapi32.dll will remain in your
system directory. This causes the LoadLibrary() call to succeed, while further calls to
functions inside this library will fail.

Surfing though the registry I found out that there is a certain registry key which exists
if the RAS is installed, and is removed when the RAS is removed. This checked out for Win95,
Win98, WinNT and Win2000 (in fact, I don’t think it’s even possible to remove the RAS from
Win2k). The only ‘problem’, is that Win9x uses another registry key then WinNT. This can
easily be solved by an OS detect though.

The code below is all that is needed to successfully detect the RAS:

int RasDetect(void)
{
  HKEY registry = NULL;
  DWORD result;
  OSVERSIONINFO version;
  /* FIXME: GetLastError zelf implementeren */
  char regkey[70];

  /* First we have to find out which OS we are running on */
  version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  /* If we get and error, we can't continue. */
  if(!GetVersionEx(&version)) return -666;

  /* Then we set the registry key we want to look at */
  /* according to the OS we detected. */

  /* NOTE: WinME uses a registry layout similair to WinNT!! */
  if (version.dwPlatformId
  == VER_PLATFORM_WIN32_WINDOWS && version.dwMinorVersion != 90)
    strcpy(regkey, "system\currentcontrolset\services"
                   "\remoteaccess\networkprovider");
  else
    strcpy(regkey,"system\currentcontrolset\services\remoteaccess");

  /* We then try to open the registry key */
  if ((result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
    regkey, 0,
    STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS
    | KEY_NOTIFY | READ_CONTROL,
    &registry))
  != ERROR_SUCCESS)
  {
    if(result == ERROR_FILE_NOT_FOUND)
    {
      RegCloseKey(registry);
      return 0; // No RAS found
    }
    else
    {
      RegCloseKey(registry);
      return -1; // Some other error
    }
  }

  RegCloseKey(registry);
  return 1; // Found RAS! Woohoo!!
}

Downloads

Download demo application – 4 Kb
Download demo source – 10 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.