Do you need to get the permissions for a share or do you need to get the ACLs
for a mapped network drive?
In the latter case you should be able to do it using
DirectoryInfo.G etAccessControl ().
In the first case you can do it using WMI:
string machine = "MachineNam e";
ConnectionOptio ns co = new ConnectionOptio ns();
co.Impersonatio n = ImpersonationLe vel.Impersonate ;
co.EnablePrivil eges = true;
ManagementScope scope = new ManagementScope ("\\\\" + machine +
"\\root\\cimv2" , co);
scope.Connect() ;
ObjectQuery query = new ObjectQuery("SE LECT * FROM
Win32_LogicalSh areSecuritySett ing");
ManagementObjec tSearcher searcher = new
ManagementObjec tSearcher(scope , query);
ManagementObjec tCollection queryCollection = searcher.Get();
foreach (ManagementObje ct m in queryCollection )
{
string shareName = "\\\\" + machine + "\\" + m["Name"];
Console.WriteLi ne(shareName);
InvokeMethodOpt ions options = new InvokeMethodOpt ions();
ManagementBaseO bject outParamsMthd =
m.InvokeMethod( "GetSecurityDes criptor", null, options);
ManagementBaseO bject descriptor =
outParamsMthd["Descriptor "] as ManagementBaseO bject;
ManagementBaseO bject[] dacl = descriptor["DACL"] as
ManagementBaseO bject[];
foreach (ManagementBase Object ace in dacl)
{
ManagementBaseO bject trustee = ace["Trustee"] as
ManagementBaseO bject;
string domain = (string) trustee["Domain"];
string name = (string)trustee["Name"];
Console.WriteLi ne(domain + "\\" + name);
}
}
HTH, Jakob.
--
http://www.dotninjas.dk
"The ants are driving me crazy" wrote:
Can anyone point me to code samples that can get the permission set
for a network drive? I tried the FileInfo and DirectoryInfo classes
but they do not seem to list what I need.