Hi Ralph,
You can do this by using WMI. I wrote the following example for you. The
example lists all shares on a given computer including the users/groups that
are granted persmisssions to the shares. The "ace" object can also give you
information about the access rights (take a look at the Win32_ACE class of
WMI on MSDN).
string machine = "YourMachine";
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
:
Hi,
how can I get the users or groups which are listed in the shared
permission of a shared folder?
Thanks,
Ralph- Zitierten Text ausblenden -- Zitierten Text anzeigen -- Zitierten Text ausblenden -- Zitierten Text anzeigen -