NetShareDel Function

Deletes a share name from a server's list of shared resources, disconnecting all connections to the shared resource.

The extended function NetShareDelEx allows the caller to specify a SHARE_INFO_0, SHARE_INFO_1, SHARE_INFO_2, SHARE_INFO_502, or SHARE_INFO_503 structure.

Syntax

C++
NET_API_STATUS NetShareDel(
  __in  LMSTR servername,
  __in  LMSTR netname,
        DWORD reserved
);

Parameters

servername [in]

Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.

This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined.

netname [in]

Pointer to a string that specifies the name of the share to delete.

This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined.

reserved

Reserved, must be zero.

Return Value

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.

Return codeDescription
ERROR_ACCESS_DENIED

The user does not have access to the requested information.

ERROR_INVALID_PARAMETER

The specified parameter is not valid.

ERROR_NOT_ENOUGH_MEMORY

Insufficient memory is available.

NERR_NetNameNotFound

The share name does not exist.

 

Remarks

This function applies only to Server Message Block (SMB) shares. For other types of shares, such as Distributed File System (DFS) or WebDAV shares, use Windows Networking (WNet) functions, which support all types of shares.

Only members of the Administrators, Server Operators, or Power Users local group, or those with Server Operator group membership, can successfully delete file shares with a call to the NetShareDel function. The Print Operator can delete printer shares.

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.

Examples

The following code sample demonstrates how to delete a share using a call to the NetShareDel function.

#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>
#pragma comment(lib, "Netapi32.lib");

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

   if(argc<3)
      printf("Usage: NetShareDel server share\n");
   else
   {
      //
      // Call the NetShareDel function to delete the share.
      //
      res=NetShareDel(argv[1], argv[2], 0);
      //
      // Display the result of the call.
      //
      if(res==0)
         printf("Share Removed.\n");
      else
         printf("Error: %u\n", res);
   }
   return;
}

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderLmshare.h (include Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll

See Also

Network Management Overview
Network Management Functions
Network Share Functions
NetShareAdd
NetShareDelEx

Send comments about this topic to Microsoft

Build date: 11/12/2009

Tags :


Page view tracker