国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

使用WMI列出Windows中某個目錄的用戶權限(C#)

2024-07-21 02:18:53
字體:
來源:轉載
供稿:網友
using system;

using system.management;

using system.collections;



class tester

{



public static void main()

{

try

{

managementpath path = new managementpath( );

path.server = ".";

path.namespacepath = @"root/cimv2";

path.relativepath = @"win32_logicalfilesecuritysetting.path='c://test'"; // using tmp as folder name



managementobject lfs = new managementobject(path);

// dump all trustees (this includes owner)

foreach (managementbaseobject b in lfs.getrelated())

console.writeline("trustee: {0} /t sid [{1}]", b["accountname"], b["sid"]);

// get the security descriptor for this object

managementbaseobject outparams = lfs.invokemethod("getsecuritydescriptor", null, null);



if (((uint)(outparams.properties["returnvalue"].value)) == 0)

{

managementbaseobject descriptor = ((managementbaseobject)(outparams.properties["descriptor"].value));

managementbaseobject[] daclobject = ((managementbaseobject[])(descriptor.properties["dacl"].value));

dumpaces(daclobject);

managementbaseobject ownerobject = ((managementbaseobject)(descriptor.properties["owner"].value));

dumpownerproperties(ownerobject.properties); // show owner properies

}

}

catch(exception e)

{

console.writeline(e);

console.readline();

}

}



static void dumpaces(managementbaseobject[] daclobject)

{

// ace masks see: winnt.h

string[] filedesc = {"file_read_data", "file_write_data", "file_append_data", "file_read_ea",

"file_write_ea", "file_execute", "file_delete_child", "file_read_attributes",

"file_write_attributes", " ", " ", " ",

" ", " ", " ", " ",

"delete ", "read_control", "write_dac", "write_owner",

"synchronize ", " ", " "," ",

"access_system_security", "maximum_allowed", " "," ",

"generic_all", "generic_execute", "generic_write","generic_read"};



foreach(managementbaseobject mbo in daclobject)

{

console.writeline("-------------------------------------------------");

console.writeline("mask: {0:x} - aceflags: {1} - acetype: {2}", mbo["accessmask"], mbo["aceflags"], mbo["acetype"]);

// access allowed/denied ace

if(mbo["acetype"].tostring() == "1")

console.writeline("denied ace type");

else

console.writeline("allowed ace type");

// dump trustees

managementbaseobject trustee = ((managementbaseobject)(mbo["trustee"]));

console.writeline("name: {0} - domain: {1} - sid {2}/n",

trustee.properties["name"].value,

trustee.properties["domain"].value,

trustee.properties["sidstring"].value);

// dump ace mask in readable form

uint32 mask = (uint32)mbo["accessmask"];

int[] m = {(int)mask};

bitarray ba = new bitarray(m);

int i = 0;

ienumerator baenum = ba.getenumerator();

while ( baenum.movenext() )

{

if((bool)baenum.current)

console.writeline( "/t[{0}]", filedesc[i]);

i++;

}

}

}



static void dumpownerproperties(propertydatacollection owner)

{

console.writeline("=============== owner properties ========================");

console.writeline();

console.writeline("domain {0} /tname {1}",owner["domain"].value, owner["name"].value);

console.writeline("sid /t{0}",owner["sidstring"].value);

console.readline();

}

}

//


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 察雅县| 民和| 调兵山市| 衡水市| 威远县| 永川市| 芦溪县| 阳泉市| 靖远县| 科技| 庆阳市| 鲜城| 五原县| 石台县| 桑日县| 托克逊县| 柳州市| 昌吉市| 金寨县| 当雄县| 临澧县| 巨鹿县| 桑植县| 宁陵县| 石渠县| 交城县| 南宁市| 正安县| 和田县| 濉溪县| 红河县| 沙坪坝区| 扬州市| 加查县| 宝丰县| 富川| 江山市| 营山县| 旌德县| 钟祥市| 紫金县|