Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')
Dim $Systems, $Shares, $sComputer, $File, $Report
$Systems = ReadFile(@ScriptDir+'\systems.txt')
$File = @ScriptDir+'\'+'system_shares.txt'
If Exist($File)
Del $File
EndIf
$Report = RedirectOutput($File,0)
For Each $sComputer In $Systems
If $sComputer
$Shares = ListSharesAndPerms($sComputer)
EndIf
Next
$Report = RedirectOutput("")
RUN 'Notepad.exe ' + $File
Function ListSharesAndPerms($sComputer)
Dim $File, $Report, $objWMIService, $colShares, $objShare
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
For Each $objShare In $colShares
If $objShare
If Not $objShare.Type = '-2147483648' And Not InStr($objShare.Name,'IPC'+'$')
$sComputer + ' ' + 'SHARE-NAME:' + ' ' + $objShare.Name + ' Path: ' + $objShare.Path ?
SharePerms('SHOW','\\'+$sComputer+'\'+$objShare.Name)
EndIf
EndIf
Next
EndFunction
Function SharePerms($cmd,$object,Optional $trustee,Optional $perms)
Dim $ADSU, $GSD, $oDacl, $Ace, $oAce
$ADSU = CreateObject("ADsSecurityUtility")
$GSD = $ADSU.GetSecurityDescriptor($object, 2, 1)
$oDacl = $GSD.DiscretionaryAcl
If $cmd = "SHOW"
For Each $Ace In $oDacl
If $Ace
$SharePerms = $SharePerms + @CRLF
"Trustee: " + $Ace.Trustee + @CRLF
"Flags: " + $Ace.AceFlags + @CRLF
"AccessMask: " + $Ace.AccessMask + @CRLF
"Type: " + $Ace.AceType + @CRLF + @CRLF
EndIf
Next
EndIf
If $cmd = "DEL"
If $trustee <> ""
For Each $Ace in $oDacl
If $Ace.trustee = $trustee
$oDacl.RemoveAce($Ace)
EndIf
Next
$GSD.DiscretionaryAcl = $oDacl
$ADSU.SetSecurityDescriptor($object, 2, $GSD, 1)
Else
Exit 1
EndIf
EndIf
If $cmd = "ADD"
If $trustee <> ""
$oAce = CreateObject("AccessControlEntry")
$oAce.Trustee = $trustee
Select
Case $perms = "READ"
$oAce.AccessMask = 1179817
Case $perms = "WRITE"
$oAce.AccessMask = 1245631
Case $perms = "FULL"
$oAce.AccessMask = 2032127
Case 1
$oAce.AccessMask = 1179817
EndSelect
$oDacl.AddAce($oAce)
$GSD.DiscretionaryAcl = $oDacl
$ADSU.SetSecurityDescriptor($object, 2, $GSD, 1)
Else
Exit 1
EndIf
EndIf
Exit @ERROR
EndFunction
Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=Chr(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction