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 ["Accentname"], B ["SID"]);
// Get the security descriptor for this Object
ManagementBaseObject Outparams = LFS.InvokeMethod ("GetSecurityDescriptor", NULL, NULL)
IF (((UINT) ("ReturnValue", Value)) == 0)
{
ManagementBaseObject descriptor = (("" "" "" "" ""); "Descriptor"]. Value);
ManagementBaseObject [] daclobject = ((ManagementBaseObject []) (Descriptor.properties ["DACL"]. Value);
DUMPACES (DACLOBJECT);
ManagementBaseObject OwnerObject = ("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 = ((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.geetenumerator ();
While (Baenum.MoveNext ())
{
IF (Bool) Baenum.current
Console.writeline ("/ T [{0}]", FileDesc [i]);
i ;
}
}
}
Static Void DumpnerProperties (PropertyDatacolection Owner)
{
Console.writeLine ("=============================================="); console .Writeline ();
Console.writeline ("Domain {0} / TName {1}", Owner ["Domain"]. Value, Owner ["Name"]. Value);
Console.writeline ("SID /T }" ,owner["sidstring"].value);
Console.readline ();
}
}
//