none
NetShareDel in netapi32.dll in Windows Server 2008 Cluster RRS feed

  • Question

  •  

    I'm trying to find a work-around for a current bug in Windows Server 2008.  In the past, I have been able to use the Win32_Share WMI class to enumerate, add and delete file shares on a remote server.  There is a known bug with a Server 2008 Failover Cluster that prevents me from using the Win32_Share WMI class to manipulate shares.

    The net share command also does not work (Net share sharename /DELETE), so that's ruled out as a possible work-around.

    The avenue that I'm going down now is using the NetShareDel function in the netapi32.dll.  Here's the function declaration I'm using in a VB.NET project:

    <DllImport("netapi32", CharSet:=CharSet.Unicode)> _  
        Public Shared Function NetShareDel _  
           (ByVal ServerName As String, _  
           ByVal NetName As String, _  
           ByVal Reserved As IntegerAs Integer 
        End Function 

    For example, if the Server 2008 Cluster has a network name of "FileServer1" and there is a share with name "user$" hosted on that server, I would call the function as such:

    Dim result as Integer  
    result = NetShareDel("FileServer1","user$",0)  
     

    This all works as anticipated.  The return value from the function is 0, indicating success and the share is in fact removed from the remote server.

    The problem I have deals with some kind of lock left on the folder.  I can't delete the folder that was previously shared because it tells me that it is in use by another program or file.

    For example, if I shared E:\Users\Department\user1 as user1$, then called the NetShareDel function to remove user1$, I can't delete the directory E:\Users\Department\user1 because it is in use.

    In troubleshooting, I tried the same thing on a Windows Server 2003 file server cluster, and have the same issue, so this seems to be a symptom of using the NetShareDel function.

    Not being an expert with using API function calls in general, is there something I'm missing that is keeping a lock on this folder after I remove the share?  Is there another workaround that I'm not considering that may be better?

    Thanks for any assistance and/or guidance.


    Just tried the same on a Windows XP machine, a Windows Server 2003 machine (non-clustered) and a Windows Server 2008 machine (non-clustered).  I created a folder, shared it out, then executed the NetShareDel function from a different machine.  The share was deleted successfully and I was able to delete the directory afterwards.  It seems this issue may be specific to clustered file servers in both Server 2003 and Server 2008. (Although, in Server 2003, I'm still able to use the Win32_Share WMI class to manage shares)
    Friday, September 12, 2008 5:44 PM

Answers

  • Here's what I ended up doing in the interim until the bug in the Win32_Share WMI class is resolved. (I haven't tried to delete a share using WMI recently but I assume that it still doesn't work).

    (1)  We applied the following hotfix to both nodes in the cluster and then proceeded to reboot both servers as you typically would to apply a hotfix in a failover cluster:

    http://support.microsoft.com/default.aspx/kb/949857

    At the top of the article, it lists Windows Server 2008 as one of the operating systems affected by it, but does not provide hotfix information for Server 2008, only Vista.  We ended up testing and using the Vista version of the hotfix on our 2008 servers.  We are still in production with no issues after applying the hotfix on October 18th, 2008 (Please don't use this as your basis for putting this into production...)

    (2)  After the hotfix was applied, the NetShareDel function in the netapi32.dll worked just fine.


    Wednesday, January 7, 2009 9:29 PM

All replies

  •  

    Hi Travis,

     

    I am researching on the issue and will update you at the earliest.

     

    Thanks,

     

    Leena

    Thursday, September 18, 2008 2:48 AM
  • Hi Travis,

     

    It seems that the problem is that the VB code is running on 2003/XP which doesn’t have the latest API from netapi32.dll.

     

    Try running  the VB code from Vista/2008 and see what happens.

     

    What’s the bug that’s preventing WMI from working?

     

    Thanks,

    Leena

     

    Monday, September 22, 2008 8:35 PM
  • Leena,

     

    The WMI bug deals specifically with the Win32_Share WMI class.  I had a call into Microsoft PSS and they told me that it will be fixed in an upcoming service pack, but other then that, we'll have to wait.  I don't know the details of the bug specifically, but I can tell you that any access to the Win32_Share WMI class on a Server 2008 Failover cluster running file sharing just plain doesn't work.

     

    The code I'm running is actually running on a Windows Vista machine.  (The Vista machine is local, the Server 2008 Machine is remote).  It has never run on a Windows XP or Windows Server 2003 machine.

     

     

    Monday, September 22, 2008 8:41 PM
  • Hi Travis,

     

    If you specify the \\computername  the NET SHARE commands should work.

     

    You can create and delete clustered shares successfully with net share but  it seems that you can’t modify any properties for a clustered share using the NET command.

     

    Thanks,

     

    Leena

     

     

    Tuesday, September 30, 2008 9:38 PM
  • Leena,

     

    The Net Share command does allow  me to create new shares, but I haven't been able to use it to delete shares.  This is why I have moved on to trying Windows API calls to delete shares.  The Win32_Share WMI class doesn't work, the Net Share command (although it allows me to *create* shares) doesn't work, and the Windows API call in netapi32.dll deletes the share, but keeps a lock on the directory until restart  or failover of the cluster, so the directory can't be deleted.

     

    Here's the console output from the active server in the cluster.  I created a new share (which worked, I verified connectivity from a remote computer), then tried to use the "Net Share sharename /DELETE" command to delete the share:

     

    Code Snippet

    C:\>net share sharetest$=e:\users\system\sharetest sharetest$ was shared successfully.


    C:\>net share sharetest$ /DELETE
    This shared resource does not exist.

    More help is available by typing NET HELPMSG 2310.


    C:\>

     

     

    I received the suggestion of using the Net Share command on an earlier forum post when originally troubleshooting this issue: 

     

    http://social.technet.microsoft.com/Forums/en-US/winserverManagement/thread/a161f53c-1386-4417-871c-e3ac3e911c83

     

    So, in summary here is what has happened so far:

    1. Unable to enumerate or delete shares with the Win32_Share WMI class (but creating shares DOES work).
    2. Tried to enumerate/delete shares with the Net Share command with the following results:
      1. Able to create shares
      2. Unable to view/list shares except for administrative shares (C$, Admin$, etc.)
      3. Unable to delete shares (as demonstrated above)
    3. Tried to delete shares using the NetShareDel method in the netapi32.dll file (Windows API) and the share does get deleted, but a lock remains on the directory until the server is restarted or failover occurs in the cluster.  This allows me to delete the share, but not to delete the directory that was shared.

    So I'm still back to my original issue, that I'm unable to programatically enumerate and delete shares on a Windows Server 2008 Failover Cluster and have still found no workaround for this.

     

    Thanks again for your help and that of any others that may be able to contribute to find a solution for this.

     

     

    Tuesday, September 30, 2008 10:25 PM
  • Any resolution here Travis? I'm running into similar things.
    Wednesday, January 7, 2009 8:51 PM
  • Here's what I ended up doing in the interim until the bug in the Win32_Share WMI class is resolved. (I haven't tried to delete a share using WMI recently but I assume that it still doesn't work).

    (1)  We applied the following hotfix to both nodes in the cluster and then proceeded to reboot both servers as you typically would to apply a hotfix in a failover cluster:

    http://support.microsoft.com/default.aspx/kb/949857

    At the top of the article, it lists Windows Server 2008 as one of the operating systems affected by it, but does not provide hotfix information for Server 2008, only Vista.  We ended up testing and using the Vista version of the hotfix on our 2008 servers.  We are still in production with no issues after applying the hotfix on October 18th, 2008 (Please don't use this as your basis for putting this into production...)

    (2)  After the hotfix was applied, the NetShareDel function in the netapi32.dll worked just fine.


    Wednesday, January 7, 2009 9:29 PM