troubleshooting Question

Verification of a script

Avatar of thechaosrealm
thechaosrealmFlag for United States of America asked on
ProgrammingWindows OSMicrosoft Development
4 Comments1 Solution529 ViewsLast Modified:
I don't have a computer system I can test this one yet, but I found this script here ( ) and would like if someone can verify what actions will come.

 - I'm looking for a script to remove all network shares, either mapped manually or by login scripts.
 - I'm looking for a way to remove all mapped printers from the server.

Please advise.
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile: Set objFile = objFSO.OpenTextFile("C:\Computers.txt")
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\SharesRemoved.log")
Do While Not objFile.AtEndOfStream
  strPC = objFile.ReadLine
  On Error Resume Next
  Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPC & "\root\cimv2")
  If Err.Number = 0 Then
    Set colShares = objWMI.ExecQuery("Select * from Win32_Share")
    For Each objShare In colShares
      Select Case UCase(objShare.Name)
        Case "IPC$", "C$", "ADMIN$", "D$", "E$"
wscript.echo "Identified protected share...not removing"
          'Do nothing
          'Uncomment the next line if you want reporting on this...
          'objOutput.WriteLine strPC & vbTab & objShare.Name & " not removed."
        Case Else
wscript.echo "removing " & objShare.Name
      End Select
      objOutput.WriteLine strPC & vbTab & objShare.Name & " removed."
    objOutput.WriteLine strPC & " could not be reached."
    On Error GoTo 0
  End If
Set objWMI = Nothing
Set objFSO = Nothing
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros