Virtual Developer Workshop: Containerized Development with Docker

Environment: CNetService was developed for Microsoft. Windows NT. platforms using Microsoft. VisualC++ 6.0

The Microsoft. Win32. API provides Windows networking (WNet) functions, providing networking capabilities for applications. The WNet functions are network independent, enabling an application to query and control network connections directly without knowledge of the underlying network transports.

CNetService is a C++ class which wraps methods around each of the WNet functions, providing an object-oriented interface to these functions, grouping common variables and structures in a single class object. This allows focusing on the network project rather than the structures required by WNet.

The following WNet functions are used in CNetService:

The CNetService class can be extended to provide access to specific keys and values, and to enhace its capabilities. Refer to the Microsoft Platform SDK: Windows Networking (WNet) documentation from the MSDN (support.microsoft.com).

CNetService contains the following methods, fully documented in the download file:

    Method Function
    Constructor Initializes the class.
    AddConnection Creates the specified network connection.
    CloseEnum Ends a network resource enumeration.
    EnumerateNext Continues an enumeration of network resources.
    EnumerateResource Continues an enumeration of resources.
    Error Value in GetLastError.
    ErrorMessage Message associated with GetLastError.
    GetNetInfo Get a pointer to NETINFOSTRUCT.
    GetNetStatus Get the network status.
    GetNetType Get the network type code.
    GetNetInfoPrinters Bit vector of valid print devices.
    GetNetInfoDrives Bit vector of valid disk devices.
    GetProviderName Returns the network provider name.
    GetUNC Retrieves the UNC representing a network share.
    NetConnect Creates the specified network connection.
    NetDisconnect Disconnect from the specified network connection.
    NetError Value of WNetGetLastError.
    NetErrorMessage Message associated with WNetGetLastError.
    NetErrorProvider Name of provider returning WNetGetLastError.
    NetUser Returns the connection owner name (account).
    NetworkInformation Information about a specific network transport.
    OpenEnum Starts an enumeration of network resources.
    OSVersion Version of the operating system currently running.
    ResourceDisplayType ResourceDisplayType from NETRESOURCE structure.
    Result Result of last operation.
    ServiceError Value in ServiceError.
    ServiceErrorMessage Message associated with ServiceError.
    UNCRemotePath Return the remote share path (see GetUNC).
    UNCRemoteServer Return the remote share name (see GetUNC).
    UniversalName Return the complete share name (see GetUNC).

Installing the Class

To use this class,

  1. Copy CNetService.cpp and CNetService.h to the same directory as your project or class libraries;
  2. Include CNetService.cpp and CNetService.h in your project;
  3. Add CNetService.h to any modules which make reference to CNetService or one of its' methods or variables. This will normally take the form of
      #include "CNetService.h"
    in the header files in which the CNetService object is declared.
  4. Include mpr.lib in the linker. In VisualC++, this is accomplished by adding mpr.lib to your project settings dialog, link tab, object/library modules entry.

Sample Application

A VisualC++ 6 workspace containing several sample projects is included with the CNetService download:

    A Windows console program which connects a local drive to a network resource.
    A Windows console program which enumerates current network resources to a console window.
    A Windows dialog which enumerates current network resources in a graphical manner.


Click here for larger image

WNetEnum is a Microsoft. Windows NT. program to enumerate current network resources in a graphical manner.


  • Enumerates current network servers, workstations and resources.

  • VisualC++ project and source code.
  • Based on CNetService class.


Download demo projects - 173 Kb
Download source - 48 Kb


  • very useful!

    Posted by Legacy on 12/16/2003 08:00am

    Originally posted by: tuc

    Very interesting and useful!!
    It's better than net view called from a bat file ;-)
    ...and compile on visual c++ 7 whitout troubles.

  • WInet&CSocket's applications

    Posted by Legacy on 03/08/2003 08:00am

    Originally posted by: Sway

    I don't quite understand what the different fields for winInet and CScoket applications. They are different things, aren't there?

    Thank you,

  • VB & WNet

    Posted by Legacy on 04/30/2001 07:00am

    Originally posted by: Jay Wheeler

    The following microsoft knowledge base article should be a good start:

    "Q189515 - WNetCOM Uses COM Object to Access WNet Functions from VB" at


  • VB& and WNet

    Posted by Legacy on 04/11/2001 07:00am

    Originally posted by: Patrick Imboden

    I haven't been able to find out how to use de WNet with Visual Basi, Is there a way... Do yo have an example.
    Thank you

  • Access denied when running WNetEnum

    Posted by Legacy on 04/09/2001 07:00am

    Originally posted by: Richard Preston

    I get the message "Access denied" when I run WNetEnum on Windows 2000 and only some domains and machines on my network will show up. I was wondering why -- I would think that my user would have enough rights to see the network structure since I can see the network using the tools provided by Microsoft.

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date