?
Solved

Shared Directories Deleted but Share Remains in Computer Management

Posted on 2008-10-08
3
Medium Priority
?
318 Views
Last Modified: 2012-05-05
I recently wrote a vbscript to delete a large number of user home directories that were inactive.  The script used the FileSystemObject.DeleteFile method.  All of the directories were deleted successfully but the share information for each of the directories still shows in Computer Manager.  What did I miss?  How can I remove the shares?  There are almost a thousand of them.  Thanks for your assistance.

RJT
0
Comment
Question by:robtroller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
jmoisy earned 750 total points
ID: 22667453
Hello,

Before delete a share folder you must remove the share. Now that all the folder are deleting you must go to the registry and delete manually all the entries for the share.

HKLM\System\CurrentControlSet\Services\lanmanserver\Shares

After you must reboot the server.

To delete a share in VBS here is the script :

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
    ("Select * from Win32_Share Where Name = 'share'")
For Each objShare in colShares
    objShare.Delete
Next

Regards,
0
 
LVL 14

Assisted Solution

by:igor-1965
igor-1965 earned 750 total points
ID: 22670546
If you have a list of the folders in the format drive:path you could remove shares by running windows command "NET SHARE <drive:path> /DELETE" for each folder.

This command works even if the folder has been deleted on the server so just amend your script to launch Windows shell with the command instead of calling for FileSystemObject.DeleteFile method.
 
0
 

Author Closing Comment

by:robtroller
ID: 31504627
Thanks Guys!  Igor, your solution would definately have worked.  Moisy, I did not have to go into the registry.  This scirpt did the trick without a reboot even though the origional directories had been deleted.  Again, thanks to both, you got me on the right track!

On Error Resume next
ServerFile = "\\nenas02\adscripts$\Nas02Shares.txt"
'Create FileSystem Object
Set objfso = CreateObject("Scripting.FileSystemObject")
'Open Target And Log Files      
Set objserverFile = objFSO.OpenTextFile(serverFile, 1)
Do While objserverFile.AtEndOfStream <> True
      strName = objserverFile.ReadLine
      strComputer = "NENas02"
      set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
      Set objShare = objWMI.Get("Win32_Share.Name='" & strName & "'")
      If Err.Number =  0 Then
            intRC = objShare.Delete
            If intRC <> 0 then
               WScript.Echo "Error deleted share: " & intRC
      Else
               WScript.Echo "Successfully deleted share " & strName
      end If
Else
      Err.Number = 0
      WScript.Echo "Skipped " & strName
End If
Loop
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question