Announcement

Collapse
No announcement yet.

delete all share folders from all workstations

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • delete all share folders from all workstations

    Hi,

    i need help to write a script that will delete all the shares that the users shared on the computers the work on.
    i can use net share "sharename" "drive:" /delete .
    the problem is that i don't know the names of shares...
    i wish i coul'd do it by gpo but i have not found it .

    any suggestions will be great!!

    Aviv Hassidim
    Sys Admin

  • #2
    Re: delete all share folders from all workstations

    You will be better off with a VBS script (not one of my skills unfortunately). The shares are held in a registry key in the HKLM subtree and could be listed by a script and deleted one by one. Obviously you would need checks in place in the script to avoid trying to delete things like C$ and IPC$ as they are required by the system.


    Tom
    For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

    Anything you say will be misquoted and used against you

    Comment


    • #3
      Re: delete all share folders from all workstations

      Originally posted by Stonelaughter View Post
      You will be better off with a VBS script (not one of my skills unfortunately). The shares are held in a registry key in the HKLM subtree and could be listed by a script and deleted one by one. Obviously you would need checks in place in the script to avoid trying to delete things like C$ and IPC$ as they are required by the system.
      Example of a batch that can do that:
      Code:
      :: This batch will delete all shared-folders shared on the local computer
      
      :: It must be executed by a member of the local group Administrators -
      :: or, you can run this batch as a computer startup script. 
      
      :: The first For-Do loop enumerate the entry names in the Shares registry key
      :: The second For-Do loop within the first loop Trims each found sharename
      :: so it can be used with the Net share command.
      
      :: note, DELIMS=<tab>
      
      @FOR /F "DELIMS=	" %%* IN (
        'REG QUERY "HKLM\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares" ^|Find/i "REG_MULTI_SZ"'
         ) DO @For /f "TOKENS=*" %%* in ('echo.%%*') DO @Net.exe Share "%%*" /delete /y
      (The system's administrative shares (c$, admin$, IPC$, ect.) are by default not present in the above registry key, so the batch will not delete these).


      \Rems

      EDIT
      Sample for a VBScript: http://forums.petri.com/showthread.p...304#post190304
      _
      Last edited by Rems; 12th December 2009, 14:23.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment

      Working...
      X