本文整理汇总了C#中System.Management.ManagementObjectSearcher.MoveNext方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.MoveNext方法的具体用法?C# ManagementObjectSearcher.MoveNext怎么用?C# ManagementObjectSearcher.MoveNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementObjectSearcher
的用法示例。
在下文中一共展示了ManagementObjectSearcher.MoveNext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFromWmi
static string GetFromWmi(string query, string column, string scope = null)
{
try
{
IEnumerator wmi = new ManagementObjectSearcher(scope, query).Get().GetEnumerator();
return wmi.MoveNext() ? ((ManagementObject)wmi.Current)[column].ToString() : null;
}
catch
{
return null;
}
}
示例2: getParentPid
/// <summary>
/// get parent pid for specified process
/// </summary>
/// <param name="cpid">child process</param>
/// <returns>uint</returns>
static uint getParentPid(int cpid)
{
string query = string.Format("SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {0}", cpid);
var results = new ManagementObjectSearcher("root\\CIMV2", query).Get().GetEnumerator();
results.MoveNext();
ManagementBaseObject queryObj = results.Current;
return (uint)queryObj["ParentProcessId"];
}
示例3: GetDriveInformation
public List<DriveInformation> GetDriveInformation()
{
var q = new WqlObjectQuery("SELECT * FROM Win32_DiskDrive");
var res = new ManagementObjectSearcher(q);
var driveNames = (from ManagementBaseObject o in res.Get() select o["Model"]?.ToString()).ToList();
var driveList = new List<DriveInformation>();
var drives = DriveInfo.GetDrives();
for (var index = 0; index < drives.Length; index++)
{
try
{
var drive = drives[index];
var driveInfo = new DriveInformation();
if (!drive.IsReady) continue;
driveInfo.Model = driveNames.ElementAtOrDefault(index) != null ? driveNames[index] : "Unknown Model";
driveInfo.Name = drive.Name;
driveInfo.FreeSpace = drive.TotalFreeSpace;
driveInfo.TotalSize = drive.TotalSize;
driveInfo.DriveType = drive.DriveType.ToString();
driveInfo.DriveFormat = drive.DriveFormat;
driveInfo.VolumeLabel = drive.VolumeLabel;
driveInfo.RootDirectory = drive.RootDirectory.ToString();
driveInfo.IsReady = drive.IsReady;
//just set it for now
driveInfo.SmartData = new List<SmartModel>();
driveInfo.Partitions = new List<PartitionModel>();
driveList.Add(driveInfo);
try
{
var mosDisks =
new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE Model = '" +
driveInfo.Model + "'").Get().GetEnumerator();
if (!mosDisks.MoveNext()) continue;
driveInfo.MediaType = mosDisks.Current.GetPropertyValue("MediaType")?.ToString() ?? "Unknown";
driveInfo.Serial = mosDisks.Current.GetPropertyValue("SerialNumber")?.ToString()?.Trim() ?? "Unknown";
driveInfo.Interface = mosDisks.Current.GetPropertyValue("InterfaceType")?.ToString() ?? "Unknown";
driveInfo.TotalPartitions = mosDisks.Current.GetPropertyValue("Partitions")?.ToString() ?? "Unknown";
driveInfo.Signature = mosDisks.Current.GetPropertyValue("Signature")?.ToString() ?? "Unknown";
driveInfo.Firmware = mosDisks.Current.GetPropertyValue("FirmwareRevision")?.ToString() ?? "Unknown";
driveInfo.Cylinders = mosDisks.Current.GetPropertyValue("TotalCylinders")?.ToString() ?? "Unknown";
driveInfo.Sectors = mosDisks.Current.GetPropertyValue("TotalSectors")?.ToString() ?? "Unknown";
driveInfo.Heads = mosDisks.Current.GetPropertyValue("TotalHeads")?.ToString() ?? "Unknown";
driveInfo.Tracks = mosDisks.Current.GetPropertyValue("TotalTracks")?.ToString() ?? "Unknown";
driveInfo.BytesPerSecond = mosDisks.Current.GetPropertyValue("BytesPerSector")?.ToString() ?? "Unknown";
driveInfo.SectorsPerTrack = mosDisks.Current.GetPropertyValue("SectorsPerTrack")?.ToString() ?? "Unknown";
driveInfo.TracksPerCylinder = mosDisks.Current.GetPropertyValue("TracksPerCylinder")?.ToString() ?? "Unknown";
}
catch (Exception)
{
//fail
}
try
{
var mosPartition =
new ManagementObjectSearcher("SELECT * FROM Win32_DiskPartition WHERE DiskIndex = '" +
index + "'").Get().GetEnumerator();
while (mosPartition.MoveNext())
{
var partion = new PartitionModel
{
Name = mosPartition.Current.GetPropertyValue("Name")?.ToString() ?? "Unknown",
Size = mosPartition.Current.GetPropertyValue("Size")?.ToString() ?? "Unknown",
BlockSize = mosPartition.Current.GetPropertyValue("BlockSize")?.ToString() ?? "Unknown",
StartingOffset =
mosPartition.Current.GetPropertyValue("StartingOffset")?.ToString() ?? "Unknown",
Index = mosPartition.Current.GetPropertyValue("Index")?.ToString() ?? "Unknown",
DiskIndex = mosPartition.Current.GetPropertyValue("DiskIndex")?.ToString() ?? "Unknown",
BootPartition = mosPartition.Current.GetPropertyValue("BootPartition")?.ToString() ?? "Unknown",
PrimaryPartition =
mosPartition.Current.GetPropertyValue("PrimaryPartition")?.ToString() ?? "Unknown",
Bootable = mosPartition.Current.GetPropertyValue("Bootable")?.ToString() ?? "Unknown"
};
driveInfo.Partitions.Add(partion);
}
}
catch (Exception)
{
//fail
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
using (var searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData"))
using (var thresSearcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_FailurePredictThresholds"))
using (var failureSearch = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_FailurePredictStatus"))
{
try
{
var searcherEnumerator = searcher.Get().GetEnumerator();
var thresSearcherEnumerator = thresSearcher.Get().GetEnumerator();
//.........这里部分代码省略.........
示例4: GetPhisicalMemory
private static int GetPhisicalMemory()
{
ManagementObjectCollection.ManagementObjectEnumerator enumerator = new ManagementObjectSearcher { Query = new SelectQuery("Win32_PhysicalMemory", "", new string[] { "Capacity" }) }.Get().GetEnumerator();
int num = 0;
while (enumerator.MoveNext())
{
ManagementBaseObject current = enumerator.Current;
if (current.Properties["Capacity"].Value != null)
{
try
{
num += int.Parse(current.Properties["Capacity"].Value.ToString());
}
catch
{
return 0;
}
}
}
return ((num / 0x400) / 0x400);
}