-- C#, Genel

C# ile WMI Kullanımı

Windows Management Instrumentation (WMI) yani Windows Yönetim Araçları. Windows ortamında uygulama geliştiriyorsanız, basit SQL sorguları ile yerel ve uzak Windows işletim sistemine ait tüm bilgilere erişilebilir. WMI için Windows ortamında derlenen hemen hemen tüm diller için referans kütüphaneleri bulunmaktadır. Bu makalemizde C# ile basit kullanım örneklerini vermeye çalışacağım.
[sql] Select * from Win32_LogicalDisk[/sql]
 

WMI Code Creator v1.0

WMI kütüphanesindeki tüm referanslardan örnek çıktılar oluşturabileceğiniz. Microsoft tarafından resmi olarak dağıtılan bir araştır. v1.0 mevcut versiyonunu aşağıdaki bağlantıdan edinebilirsiniz. WMI Code Creator ile C#, VB.NET ve VB Script için kod örnekleri alabilirsiniz. Örnek bir C# çıktısı;

 
[php]using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_LogicalDisk WHERE BlockSize =");

foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("———————————–");
Console.WriteLine("Win32_LogicalDisk instance");
Console.WriteLine("———————————–");
Console.WriteLine("Access: {0}", queryObj["Access"]);
Console.WriteLine("Availability: {0}", queryObj["Availability"]);
Console.WriteLine("BlockSize: {0}", queryObj["BlockSize"]);
Console.WriteLine("Caption: {0}", queryObj["Caption"]);
Console.WriteLine("Compressed: {0}", queryObj["Compressed"]);
Console.WriteLine("Description: {0}", queryObj["Description"]);
Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
Console.WriteLine("DriveType: {0}", queryObj["DriveType"]);
Console.WriteLine("ErrorCleared: {0}", queryObj["ErrorCleared"]);
Console.WriteLine("ErrorDescription: {0}", queryObj["ErrorDescription"]);
Console.WriteLine("ErrorMethodology: {0}", queryObj["ErrorMethodology"]);
Console.WriteLine("FileSystem: {0}", queryObj["FileSystem"]);
Console.WriteLine("FreeSpace: {0}", queryObj["FreeSpace"]);
Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);
Console.WriteLine("MediaType: {0}", queryObj["MediaType"]);
Console.WriteLine("Name: {0}", queryObj["Name"]);
Console.WriteLine("NumberOfBlocks: {0}", queryObj["NumberOfBlocks"]);
Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
Console.WriteLine("QuotasDisabled: {0}", queryObj["QuotasDisabled"]);
Console.WriteLine("QuotasIncomplete: {0}", queryObj["QuotasIncomplete"]);
Console.WriteLine("QuotasRebuilding: {0}", queryObj["QuotasRebuilding"]);
Console.WriteLine("Size: {0}", queryObj["Size"]);
Console.WriteLine("Status: {0}", queryObj["Status"]);
Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);

Console.WriteLine("SystemName: {0}", queryObj["SystemName"]);
Console.WriteLine("VolumeDirty: {0}", queryObj["VolumeDirty"]);
Console.WriteLine("VolumeName: {0}", queryObj["VolumeName"]);

}
}
catch (ManagementException e)
{
MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
}
}
}
}[/php]
WMI Code Creator v1.0 indirme bağlantısı
http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx

Python ile ilgilenenler için wmi
http://timgolden.me.uk/python/wmi/tutorial.html