Solved

Shared Directories Deleted but Share Remains in Computer Management

Posted on 2008-10-08
3
316 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 250 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 250 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

726 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