Marza has asked for the wisdom of the Perl Monks concerning the following question:

This "process" started out as an upgrade of the big servers. We could not do a simple shutdown migrate data and boot the new server(long story).

One of the things the users were told was to re-map their drives. Many did but of course many did not.

What I wanted to do was to list stuff that people have mounted and then issue remote delete of the dead shares.

I have nosed around lanman, netresource, win32api, and fileop I got a couple ways to get a list but does the ability to remote delete a share even exist?

My head is spinning so I will have to walk away from the terminal for awhile. It is probably staring my in the face.

  • Comment on Listing and removing mounted shares remotely?

Replies are listed 'Best First'.
Re: Listing and removing mounted shares remotely? (server alias)
by grinder (Bishop) on Feb 28, 2003 at 09:25 UTC

    Taking a lateral approach to your problem...

    If I understand you correctly, you used to have a server named s1, and people mapped drives to things like \\s1\public. These days s1 has been retired (or you want to retire it), and now you have a brand new server named s2, and people should now refer to \\s2\public.

    You could configure s2 to resolve the name s1 as itself, via a netbios alias. To do this you just have to create a registry entry on s2:

    HKEY_Local_Machine\System\CurrentControlSet\Services\LanmanServer\Parameters

    Then create a REG_SZ key named OptionalNames and set its value to "s1". If you make it a REG_MULTI_SZ instead, you could then add multiple aliases.

    This will give you the breathing space you need to clean up the shares in the way you see fit (I don't think you're going to be able to do it remotely).


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: Listing and removing mounted shares remotely?
by theorbtwo (Prior) on Feb 28, 2003 at 04:14 UTC

    I suspect the correct way to remove a share remotely is to remotely remove the registry entry listing the share. Of course, that requires remote registry access. Like I said, though, only a suspicition.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      I thought of that with the TieRegistry mod. I did locate the point where you find reference and deleted it. But It appears you have to do a reboot for it to take. Problem is I can't with the machines in question.

Re: Listing and removing mounted shares remotely?
by Thelonius (Priest) on Feb 28, 2003 at 04:45 UTC
    Isn't NetShareDel in Win32::NetResource what you want?

      That only seems to work with shares that are local to the machine. I tried a few things for the remote mounts, and it does not work.

Re: Listing and removing mounted shares remotely?
by blm (Hermit) on Feb 28, 2003 at 13:33 UTC

    I have been using the IADsFileShare interface to create shares at work. After reading your question I decided to read up on it to see whether it was appropriate for deleting shares remotely instead. This says that it can represent shares remotely and here I found the code to do delete shares using this interface written in vbscript. I simply translated it to perl and tested it locally under Windows 2000. Unfortunately I only have one Windows machine so I can't test it remotely. It uses ADSI which I think you need to download and install in on NT4 but is already there under Windows 2000. I don't know about Win 9x. You didn't say what OS you were using.

    Here is my perl translation

    use Win32::OLE; my $share_name = "dev"; my $machine_name = "FIREBALL"; my $server = Win32::OLE->GetObject("WinNT://FIREBALL/lanmanserver") or die $!; $server->Delete("Fileshare", $share_name)

    Note that this interface has a CurrentUserCount property that could tell you how many people are using the share.

    Please let me know how it goes!