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 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


Comments

  • How for the wireless modem which is accessed through a USB port?

    Posted by Legacy on 05/17/2002 12:00am

    Originally posted by: J.K Yi

    I'm going to use a wireless modem for internet. 
    
    

    I couldn't find out Device Type(RASDT_Modem, RASDT_Isdn, etc...) for the wireless modem.

    How do i detect the wireless modem which is accessed through a USB port?

    Reply
  • WIN 2K RAS binding with Network

    Posted by Legacy on 12/28/2000 12:00am

    Originally posted by: skyboarg

    I had disabled RAS client bound to my network adapter while

    i was browsing internet,after that when i login to my win2k

    i could not dial out , it gives me error code


    error code:797 the connection failed because the modem was not found.Please make sure that the modem or other connecting device is installed.

    My modem diagnostics works fine, even i tried uninstalling and the plug and play picked up the modem.

    But when i look in services the RRAS was running, RAS admin was running.

    How do i Bind the RAS to my Dial up Network?


    Any ideas!!!!!!!!!

    Reply
  • Detecting Windows ME DUN...doesn't fail if DUN is removed...

    Posted by Legacy on 11/14/2000 12:00am

    Originally posted by: Jon Peddycord

    That code doesn't appear to work if Dun is installed on ME and then removed. It appears that the RemoteAccess key stays there after the removal of DUN. That's what I found anyway...any ideas ?

    Did a little more research on ME...
    It appears that if you check for HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\ControlPanel\NameSpace\{992CFFA0-F557-101A-88EC-00DD010CCC48} (The control panel applet) that you can accurately tell if the it's loaded/or not in ME.

    If you see any problems with this method...please let me know...


    Reply
  • How can I start the installroutine for RAS if it is not installed up to now ?

    Posted by Legacy on 10/24/2000 12:00am

    Originally posted by: Jochen Schroer

    Is there a way to start the installroutines for installing RAS if I find out that it is not installed up to now ?

    Best regards,
    Jochen

    Reply
  • RasDetect() does not work Under WindowsME

    Posted by Legacy on 10/12/2000 12:00am

    Originally posted by: David Fields

    BOOL RasDetect()

    Does not work under WindowsME

    Reply
  • How about detecting a TCP/IP Binding to Dialup-Adapter?

    Posted by Legacy on 01/30/2000 12:00am

    Originally posted by: Oliver

    I'm able to detect if the Dialup adapter is bound to tcpip in the win9x registry. However, I need to do the same thing for the winNT and win2k registry. Any ideas?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 19, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device …

  • As everyone scrambles to protect customers and consumers from the Heartbleed virus, there will be a variety of mitigating solutions offered up to address this pesky bug. There are a variety of points within the data path where solutions could be put into place to mitigate this (and similar) vulnerabilities and customers must choose the most strategic point in the network at which to deploy their selected mitigation. Read this white paper to learn the ins and outs of mitigating the risk of Heartbleed and the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds