'############################################################
'#Script code For finding Shared Folder And It's permission. #
'#Copy this code to notepad and save it as ScriptFile.vbs. #
'#The Code will take take 3 arguments: 1. Server Host Name, #
'#2. User name (User names must be always in- #
'#ComputerName\UserName Or DomainName\UserName) #
'#Note: Do Not run this script under wscript. Alwarsy run in #
'#cscript mode (in Command Prompt). #
'#Wish You all Happy Scripting. Enjoy !!! #
'############################################################
On Error Resume Next
Set colNamedArguments = WScript.Arguments.Named
strComputer = colNamedArguments.Item("server")
strUser = colNamedArguments.Item("usr")
strPwd = colNamedArguments.Item("pwd")
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set ObjWMIService = objSWbemLocator.ConnectServer(strComputer,"root\CIMV2",strUser,strPwd)
Set ColComp = ObjWMIService.ExecQuery ("Select Name from Win32_ComputerSystem")
For Each objComp In ColComp
Set ColShares = ObjWMIService.ExecQuery ("Select * From Win32_Share")
On Error Resume Next
For Each objShare In ColShares
Set ColSharesPerm = ObjWMIService.ExecQuery ("Associators of {Win32_Share.Name='" & objShare.Name &"'}" & _
"Where RESULTCLASS = Win32_LogicalShareSecuritySetting")
On Error Resume Next
For Each objSharesperm In ColSharesPerm
intRtn = objSharesperm.GetSecurityDescriptor (wmiSecurityDescriptor)
colDACLs = wmiSecurityDescriptor.DACL
For Each objACE In colDACLs
Set objUserGroup = objACE.Trustee
Select Case objACE.AccessMask
Case 1179817 strPermission = "READ"
Case 1245631 strPermission = "CHANGE"
Case 2032127 strPermission = "FULL CONTROL"
End Select
WScript.Echo objComp.Name & "," & strComputer & ", " & objSharesperm.Name & ", " & objShare.Path & ","& UCase(objUserGroup.Name)& "," & UCase(objUserGroup.Domain) &" ," & strPermission
Next
Next
Next
Next
<message edited by raghavendra_2512 on Thursday, September 08, 2011 4:52 AM>