[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Shared Directories Deleted but Share Remains in Computer Management

Posted on 2008-10-08
3
Medium Priority
?
322 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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