468,101 Members | 1,420 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

determine network directory permissions

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.

Feb 12 '07 #1
1 1527
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.GetAccessControl().

In the first case you can do it using WMI:

string machine = "MachineName";
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
co.EnablePrivileges = true;

ManagementScope scope = new ManagementScope("\\\\" + machine +
"\\root\\cimv2", co);
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM
Win32_LogicalShareSecuritySetting");

ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);

ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
string shareName = "\\\\" + machine + "\\" + m["Name"];
Console.WriteLine(shareName);

InvokeMethodOptions options = new InvokeMethodOptions();

ManagementBaseObject outParamsMthd =
m.InvokeMethod("GetSecurityDescriptor", null, options);
ManagementBaseObject descriptor =
outParamsMthd["Descriptor"] as ManagementBaseObject;

ManagementBaseObject[] dacl = descriptor["DACL"] as
ManagementBaseObject[];

foreach (ManagementBaseObject ace in dacl)
{
ManagementBaseObject trustee = ace["Trustee"] as
ManagementBaseObject;
string domain = (string) trustee["Domain"];
string name = (string)trustee["Name"];

Console.WriteLine(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.

Feb 13 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stanley J, Mroczek | last post: by
1 post views Thread by brian.oneil2 | last post: by
2 posts views Thread by Peter O'Reilly | last post: by
4 posts views Thread by Kim Kragh | last post: by
2 posts views Thread by Tom Wells | last post: by
2 posts views Thread by Jerad Rose | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.