我知道可以用net share 共享文件名 /delete进行删除,但是如果另一台机器已经打开了这个共享目录,就会总是要弹出对话框询问你是否继续,怎样可以默认为继续呢?就是默认为删除共享,无论是否有人打开这个目录。

解决方案 »

  1.   

    NetShareDel
    The NetShareDel function deletes a share name from a server's list of shared resources, disconnecting all connections to the shared resource.Security Requirements
    Only members of the Administrators or Account Operators local group or those with Communication, Print, or Server operator group membership can successfully execute NetShareDel. The Print operator can delete only Printer queues. The Communication operator can delete only communication-device queues.NET_API_STATUS NetShareDel(
      LPWSTR servername,  
      LPWSTR netname,     
      DWORD reserved      
    );
     
    Parameters
    servername 
    Pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer. 
    netname 
    Pointer to a Unicode string containing the network name of the share to delete. 
    reserved 
    Reserved, must be zero. 
    Return Values
    If the function returns account information, the return value is NERR_Success.If the function fails, the return value is one of the following error codes.Value Meaning 
     
    ERROR_ACCESS_DENIED The user does not have access to the requested information. 
    ERROR_INVALID_PARAMETER The specified parameter is invalid. 
    ERROR_NOT_ENOUGH_MEMORY Insufficient memory is available. 
    NERR_NetNameNotFound The sharename does not exist. 
    QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Unsupported.
      Header: Declared in lmshare.h.
      Import Library: Use netapi32.lib (Windows NT) or svrapi.lib (Windows 95).See Also
    Networking (Net) Overview, Net Functions, NetShareAdd 
      

  2.   

    yonghengdizhen(等季节一过,繁花就凋落') 能贴出例子来吗?
    非常感谢拉
      

  3.   

    to ryuginka(ryuginka):
      fso怎么用呢?我只要实现把共享删除就可以了,用哪种方法都没关系,关键是要自动,并且即使该目录已经有人打开也可以删除共享,而且要不重启
      

  4.   

    我已经实现了,哈哈,就是用的
    '删除共享(返回0 表示成功)
    '参数:
    'sServer       计算机名
    'sShareName    共享名
    Private Function DelShare(sServer As String, _
                              sShareName As String) As Long
       
       Dim lngServer   As Long       '计算机名
       Dim lngNetname  As Long       '共享名   lngServer = StrPtr(sServer)      '转成地址
       lngNetname = StrPtr(sShareName)   '删除共享
       DelShare = NetShareDel(lngServer, lngNetname, 0)大家一起来试试吧。呵呵,结贴喽
      

  5.   

    被打开的共享可以先结束共享Session再删除的
      

  6.   

    被打开的共享如何先结束Session呢?