//win32_logicaldisk
//匯入dll:解決方案 ==> 引用 ==> 添加引用 ==> COM ==> System.Management.dll --C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
using System;
using System.Management;
class disk //資料管理對象
{
public static void Main()
{
//建立 C: 的執行個體
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
Console.WriteLine("磁碟大小"+disk["Size"]+"bytes"); //列印C:大小,單位bytes
}
}
確定電腦名稱或 IP 地址是實體電腦還是虛擬 IP 地址 CIMV2:Win32_ComputerSystem
在遠端電腦上運行進程 CIMV2:Win32_Process
確定遠端電腦中是否存在某個目錄 CIMV2:Win32_Directory
停止/啟動 IIS System.Diagnostics.Process
將程式集添加到全域組件快取 (GAC) System.Diagnostics.Process
註冊和配置 GAM 組件 COMAdmin 目錄 (COM 1.0)
建立 Web 網站 System.DirectoryServices.DirectoryEntry
//可以用此方法來選擇集合中的部份記錄 "SELECT * FROM Win32_Service WHERE Name = 'ServiceName'",
"Win32_LogicalDisk" 類 //通過它我們可以查看到本地磁碟機
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * From Win32_LogicalDisk "); //查詢
ManagementObjectCollection queryCollection = query.Get(); //Get擷取集合并賦給 Collention
foreach ( ManagementObject mo in queryCollection) //偏曆集合
{
Console.WriteLine("type:"+mo["DriveType"].ToString());
sConsole.WriteLine("Drive: " + mo["Name"].ToString()); //列印出所有磁碟機
}
"Win32_Environment" 類 //環境變數
using System;
using System.Management;
public class EnumerateInstances
{
public static void Main()
{
SelectQuery query = new SelectQuery("Win32_Environment");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementBaseObject envVar in searcher.Get())
Console.WriteLine("Variable : {0}, Value = {1}",envVar["Name"],envVar["VariableValue"]);
}
}
"Win32_OperatingSystem" 類 //作業系統資訊
Console.WriteLine( "作業系統: " + mo["Caption"]);
Console.WriteLine( "版本號碼: " + mo["Version"]);
Console.WriteLine( "製造商: " + mo["Manufacturer"]);
Console.WriteLine( "電腦名稱: " +mo["csname"]);
Console.WriteLine("Windows目錄: " + mo["WindowsDirectory"]);
"Win32_Service" 類 //系統服務
//輸出預設網站的目錄結構
using System;
using System.DirectoryServices;
class IISFolderList
{
static void ListFolder(DirectoryEntry paraEntry, int paraIndent)
{
for(int i=paraIndent; i>0; i--)
Console.Write(' ');
Console.WriteLine(paraEntry.Name);
paraIndent++;
foreach(DirectoryEntry tempEntry in paraEntry.Children)
ListFolder(tempEntry,paraIndent);
paraEntry.Dispose();
}
static void Main(string[] args)
{
ListFolder(new DirectoryEntry("IIS://localhost/W3SVC/1/Root"),0);
}
}