65.9K
CodeProject is changing. Read more.
Home

Exploring Network Configuration with the INetCfg COM Interface

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.33/5 (2 votes)

Aug 24, 2007

CPOL

1 min read

viewsIcon

46116

downloadIcon

814

Getting information about installed network drivers on a PC.

Screenshot - Driver_Found.jpg

Introduction

To get information about the installed network devices, the COM interface INetCfg and some other interfaces can be used.

Background

My problem was to prove that a special driver is available on a PC. For that, I looked at the snetcfg.exe sample from Microsoft, but it didn't work for me. So, I explored the code and found that it used the INetCfg COM interface. But, I didn't find good documented code at all, so I made myself a class.

Using the Code

For using the code, it is essential to have the SDK and the DDK (or WDK) from Microsoft to have all the files installed and the right paths set so all the files can be found. I have made remarks on the most important areas:

//DDK/WDK
#include <Netcfgx.h>
#include <comdef.h>
//Platform SDK
#include <devguid.h>

Before using it, you got to create the internal COM objects. If it doesn't work, may be COM errors can help you.

//Creating the COM-instance
m_NetCfg.Init( L"Codeproject Sample", false );

My final use:

is to check whether a driver can be accessed via the COM interfaces:

HRESULT hr = m_NetCfg.FindComponentDisplayName( bs, csDisplay );
if( IS_OK( hr ) )
{
    cs.Format( "Driver found. Displayname is %s", csDisplay );
}
else
{
    cs.Format( "Error in NetCfg. COM-Message: %s", m_NetCfg.GetLastErrorMessage() );
}

In the error part, you can see my error text function used to enhance usability.

Points of Interest

It was fun to see COM work for me as I wrote the code. Because I didn't find much at CP about INetCfg, I decided to publish this article. I hope it helps, as I have often found help here.

History

  • 1.0: 23 Aug., 2007: Initial release.