CNetService

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:

    WNetAddConnection3
    WNetGetConnection
    WNetCancelConnection2
    WNetEnumResource
    WNetCloseEnum
    WNetOpenEnum
    WNetGetNetworkInformation
    WNetGetProviderName
    WNetGetResourceInformation
    WNetGetUniversalName
    WNetGetUser
    WNetGetLastError
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:

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

WNetEnum


Click here for larger image

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

Features:

  • Enumerates current network servers, workstations and resources.

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

Downloads

Download demo projects - 173 Kb
Download source - 48 Kb


Comments

  • very useful!

    Posted by Legacy on 12/16/2003 12: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.

    Reply
  • WInet&CSocket's applications

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

    Originally posted by: Sway

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

    Thank you,

    Reply
  • VB & WNet

    Posted by Legacy on 04/30/2001 12: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

    http://support.microsoft.com/support/kb/articles/Q189/5/15.ASP

    Reply
  • VB& and WNet

    Posted by Legacy on 04/11/2001 12: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

    Reply
  • Access denied when running WNetEnum

    Posted by Legacy on 04/09/2001 12: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.

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

Top White Papers and Webcasts

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

  • 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