We help IT Professionals succeed at work.

Deleting Orphan User Shares from Windows 2000

rwhittle
rwhittle asked
on
819 Views
Last Modified: 2013-12-23
Hello,

I have a number of user shares that were deleted from the command prompt but the shares are still in the registry.

Orphaned Share -  IF you have a directory shared and you delete the Directory from a Command prompt or script, the share will stay behind in the Registry.

I need a utility or a way to list and delete these orphaned shares from the windows 2000 server.  Thanks in advance.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks, I see the key but I have about 2500 users to delete.  There are also new users shares in the group also. What I would love is a utility that shows all the orphaned shares and I select them then delete.
CERTIFIED EXPERT

Commented:
@echo off
:: delOrpSH.cmd
:: remove all orphaned share
:: by Gastone Canali
:: v 0.1
::
setlocal
set line=-------------------------------------------------------------------------------
set bk=c:\sharesBkUp.reg
if exist %bk% goto :_BKpresent
echo %line%
echo.
echo Backup the registry keys in %bk%
REG EXPORT HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares %bk%
echo %line%
echo Windows Registry Editor Version 5.00>c:\delorphanshare.reg
echo. >>c:\delorphanshare.reg
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares] >>c:\delorphanshare.reg
for /f  "tokens=1 delims==" %%z in ('type %bk%^|find "="^|find "hex(7)"') do (
   call:_delSH %%z
)
echo.>>c:\delorphanshare.tmp
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares\Security] >>c:\delorphanshare.tmp
type c:\delorphanshare.reg|find "=" >>c:\delorphanshare.tmp
type c:\delorphanshare.tmp>>c:\delorphanshare.reg
echo.
echo Run regedit c:\delorphanshare.reg
echo to remove ALL orphaned shares
echo %line%
goto :_END

:_delSH
   for /f "tokens=4 delims=="  %%a in ('reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares /v %1 ^| find "CSCFlags"')  do (
     for /f "tokens=1 delims=0"  %%b in ('echo %%a') do (
      if not exist %%b\NUL (
        echo ORPHAN SHARE: %%b IN  HKLM\SYS\CurConSet\Services\lanmanserver\Shares\%1
      echo %1=->>c:\delorphanshare.reg
      )
     )      
   )
goto :_EOF

:_BKpresent
echo I don't want to overwrite backup %bk%!! move your backup in a safe location!!
:_END
:_EOF
CERTIFIED EXPERT

Commented:
Have you tried the script?
Gas

Author

Commented:
Thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.