Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim boolCode : Dim a : Dim b
Dim objshell : Set objshell = CreateObject("WScript.Shell")
Dim objfso : Set objfso = CreateObject("Scripting.FileSystemObject")
' change the path to your list text file
Dim objlist : Set objlist = objfso.OpenTextFile("\\dc\share\list.txt", ForReading)
' change the path to the path to save your report
Dim objreport : Set objreport = objfso.OpenTextFile("\\dc\share\report.txt", ForWriting)
Do Until objlist.AtEndOfStream
Dim strComputer : strComputer = objlist.ReadLine
objreport.WriteLine strComputer
objreport.writeline "***************"
If Ping(strComputer) = True Then
On Error Resume Next
Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & _
strComputer & "\root\cimv2")
If Err.Number <> 0 Then
Err.Clear
objreport.WriteLine "Unable to connect to " & strComputer & vbcrlf
On Error GoTo 0
Else
On Error GoTo 0
End If
On Error Resume Next
Dim colItems : Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalShareSecuritySetting")
If Err.Number <> 0 Then
Err.Clear
objreport.WriteLine "Probably Not Enoughf Permission On " & strComputer & vbcrlf
Else
On Error goto 0
End If
Dim objItem, intRtn, wmiSecurityDescriptor
Dim colDACLs, objACE, objUserGroup, strPermission
For Each objItem In colItems
'objreport.WriteLine "Share Name: " & objItem.Name
intRtn = objItem.GetSecurityDescriptor(wmiSecurityDescriptor)
colDACLs = wmiSecurityDescriptor.DACL
For Each objACE In colDACLs
Set objUserGroup = objACE.Trustee
If UCase(objUserGroup.Name) = "EVERYONE" Then
a = true
' objreport.WriteLine vbTab & "User/Group that has access: " & UCase(objUserGroup.Name)
End if
Select Case objACE.AccessMask
Case 1179817 strPermission = "READ"
Case 1245631 strPermission = "CHANGE"
Case 2032127 strPermission = "FULL CONTROL"
End Select
If strPermission = "FULL CONTROL" Then
b = true
' objreport.WriteLine vbTab & "Permission: " & strPermission & VbCrLf
End If
If a = True And b = True Then
objreport.WriteLine "Share Name: " & objItem.Name
objreport.WriteLine vbTab & "User/Group that has access: " & UCase(objUserGroup.Name)
objreport.WriteLine vbTab & "Permission: " & strPermission & vbCrLf
End if
a = false
b = false
Next
Next
Else
objreport.WriteLine "Unable to ping " & strComputer & VbCrLf
End If
Loop
objreport.Close
' change the mailsend syntax as you need
objshell.Run("MAILSEND -d (Email service) -smtp 192.168.0.200 -t (youremail) -f (Email again) -sub netuser")
WScript.Echo "Finished"
Function Ping(strComputer)
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
|