Platform SDK: Network Management

NetShareCheck

The NetShareCheck function checks whether or not a server is sharing a device.

Security Requirements

No special group membership is required to successfully execute the NetShareCheck function.

NET_API_STATUS NetShareCheck(
  LPWSTR servername,  
  LPWSTR device,      
  LPDWORD type        
);

Parameters

servername
[in] Pointer to a Unicode string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
device
[in] Pointer to a Unicode string specifying the name of the device to check for shared access.
type
[out] Pointer to an address that receives the type of the shared device. This parameter is set only if the function returns successfully. This parameter can be one of the following values.
Value Meaning
STYPE_DISKTREE Disk drive
STYPE_PRINTQ Print queue
STYPE_DEVICE Communication device
STYPE_IPC Interprocess communication (IPC)
STYPE_SPECIAL Special share reserved for interprocess communication (IPC$) or remote administration of the server (ADMIN$). Can also refer to administrative shares such as C$, D$, E$, and so forth. For more information, see the network management share functions.

Return Values

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value can be one of the following error codes.

Value Meaning
ERROR_NOT_ENOUGH_MEMORY Insufficient memory is available.
NERR_DeviceNotShared The device is not shared.

Remarks

The following code sample demonstrates how to check whether a server is sharing a device, using a call to the NetShareCheck function. The function returns the type of device being shared, as described in the preceding documentation for the type parameter.

#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>

void wmain( int argc, TCHAR *argv[ ])
{
   NET_API_STATUS res;
   DWORD devType = 0;

   if(argc<3)
      printf("Usage: NetShareCheck server device\n");
   else
   {
      //
      // Call the NetShareCheck function.
      //
      res=NetShareCheck(argv[1], _wcsupr(argv[2]), &devType);
      //
      // If the function succeeds, inform the user.
      //
      if(res==0)
         printf("Device is shared as type %u.\n",devType);
      //
      // Otherwise, print the error.
      //
      else
         printf("Error: %u\n", res);
   }
   return;
}

If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management share functions. For more information, see IADsFileShare.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Lmshare.h; include Lm.h.
  Library: Use Netapi32.lib.

See Also

Network Management Overview, Network Management Functions, Share Functions, NetShareEnum, NetShareGetInfo