.NET

xiaoxiao2021-03-06  67

Using

System;

Using system.management;

Using system.collections;

Class Tester

{

Public static void main ()

{

Try

{

// managementPath class, provide a path for analysis and generating WMI objects

ManagementPath path = new managementPath ();

// managementPath.server Gets or sets the server part of the path

Path.server = "."

// managementPath.namespacePath Gets or sets the namespace of the path

Path.namespacepath = @ "root / cimv2";

// managementPath.RELATIVEPATH Gets or sets relative path: only contains class names and keys

Path.RELATIVEPATH = @ "Win32_LogicalFileSecuritySetting.Path = 'c: // Test'"; // USING TMP As Folder Name

// managementObject represents data management objects

ManagementObject LFS = New ManagementObject (PATH);

// Dump All Trustees (this Includes Owner)

// mangegmentBaseObject includes the basic element of the management object to use as a base class for more specific management object classes

// managementObject.getrelated () Get a collection of objects related to this object (contact object)

FOREACH (ManagementBaseObject B IN lfs.getrelated ())

Console.writeline ("Trustee: {0} / T SID [{1}]", B ["Accentname"], B ["SID"]);

// Get the security descriptor for this Object

// managementObject.invokeMethod to the object call method

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 ("================================================================================================00

Console.writeLine ();

Console.writeline ("Domain {0} / TName {1}", Owner ["Domain"]. Value, Owner ["Name"]. Value);

Console.writeline ("SID /T }" ,owner["sidstring"].value);

Console.readline ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-109887.html

New Post(0)