Pet*_*y B 3 c# permissions share folder-permissions
是否可以读取分配给共享文件夹的共享权限?我能够在本地安全设置programmaticaly(在右键单击>属性>安全性下找到的)读取没问题.但是,我想知道如何在右键单击>共享和安全...>权限下读取权限
这是我想要阅读的权限的图像:
这可能吗?如果有帮助,我正在运行XP Pro机器.
编辑:
按我的回答,我能够通过全部股份进行迭代,并获得访问您(即运行程序的人)对这一份额,但还没有找到一种方法来读取权限,其他人都在该共享.这是使用Win32_Share类完成的,但它没有获取其他用户的共享权限的选项.如果有人有任何有用的提示,将是一个巨大的帮助.
小智 8
通过扩展Petey B采用的方法,我能够实现这一点.另外,请确保运行此代码的进程模拟服务器上的特权用户.
using System;
using System.Management;
...
private static void ShareSecurity(string ServerName)
{
ConnectionOptions myConnectionOptions = new ConnectionOptions();
myConnectionOptions.Impersonation = ImpersonationLevel.Impersonate;
myConnectionOptions.Authentication = AuthenticationLevel.Packet;
ManagementScope myManagementScope =
new ManagementScope(@"\\" + ServerName + @"\root\cimv2", myConnectionOptions);
myManagementScope.Connect();
if (!myManagementScope.IsConnected)
Console.WriteLine("could not connect");
else
{
ManagementObjectSearcher myObjectSearcher =
new ManagementObjectSearcher(myManagementScope.Path.ToString(), "SELECT * FROM Win32_LogicalShareSecuritySetting");
foreach(ManagementObject share in myObjectSearcher.Get())
{
Console.WriteLine(share["Name"] as string);
InvokeMethodOptions options = new InvokeMethodOptions();
ManagementBaseObject outParamsMthd = share.InvokeMethod("GetSecurityDescriptor", null, options);
ManagementBaseObject descriptor = outParamsMthd["Descriptor"] as ManagementBaseObject;
ManagementBaseObject[] dacl = descriptor["DACL"] as ManagementBaseObject[];
foreach (ManagementBaseObject ace in dacl)
{
try
{
ManagementBaseObject trustee = ace["Trustee"] as ManagementBaseObject;
Console.WriteLine(
trustee["Domain"] as string + @"\" + trustee["Name"] as string + ": " +
ace["AccessMask"] as string + " " + ace["AceType"] as string
);
}
catch (Exception error)
{
Console.WriteLine("Error: "+ error.ToString());
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)