thechaosrealm
asked on
Verification of a script
I don't have a computer system I can test this one yet, but I found this script here ( https://www.experts-exchange.com/questions/22544648/Remove-all-shares-in-a-machine.html ) 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.
- 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
objShare.Delete
End Select
objOutput.WriteLine strPC & vbTab & objShare.Name & " removed."
Next
Else
objOutput.WriteLine strPC & " could not be reached."
On Error GoTo 0
End If
Loop
objOutput.Close
objFile.Close
Set objWMI = Nothing
Set objFSO = Nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just confirmed - WMI version works on Vista as well as XP (in case you had that requirement).
ASKER