本文整理汇总了C#中System.Management.ManagementObjectSearcher.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.Cast方法的具体用法?C# ManagementObjectSearcher.Cast怎么用?C# ManagementObjectSearcher.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementObjectSearcher
的用法示例。
在下文中一共展示了ManagementObjectSearcher.Cast方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getJavaServerID
private void getJavaServerID()
{
string query = "SELECT ProcessId FROM Win32_Process WHERE Name = 'java.exe' AND CommandLine LIKE '%StarMade%'";
List<Process> servers = null;
using (var results = new ManagementObjectSearcher(query).Get())
servers = results.Cast<ManagementObject>()
.Select(mo => Process.GetProcessById((int)(uint)mo["ProcessId"]))
.ToList();
processID = servers[0].Id;
}
示例2: Stop
public static void Stop()
{
const string query = "SELECT ProcessId "
+ "FROM Win32_Process "
+ "WHERE Name = 'java.exe' "
+ "AND CommandLine LIKE '%fuseki-server.jar%'";
List<Process> servers = null;
using (var results = new ManagementObjectSearcher(query).Get())
servers = results.Cast<ManagementObject>()
.Select(mo => Process.GetProcessById((int)(uint)mo["ProcessId"]))
.ToList();
foreach (var process in servers)
{
process.Kill();
}
}
示例3: GetProcessStartAnalyticsData
private static MyProcessStartAnalytics GetProcessStartAnalyticsData()
{
MyProcessStartAnalytics data = new MyProcessStartAnalytics();
var cpus = new ManagementObjectSearcher("root\\CIMV2", "SELECT Name FROM Win32_Processor").Get();
// We're just reporting the first
var cpuName = cpus.Cast<ManagementObject>().First()["Name"].ToString();
var memoryInfo = new WinApi.MEMORYSTATUSEX();
WinApi.GlobalMemoryStatusEx(memoryInfo);
var deviceName =
MyVideoSettingsManager.Adapters[MyVideoSettingsManager.CurrentDeviceSettings.AdapterOrdinal]
.Name;
data.OsVersion = Environment.OSVersion.VersionString;
data.CpuInfo = cpuName;
data.GpuInfo = deviceName;
data.GameVersion = MyFinalBuildConstants.APP_VERSION_STRING.ToString();
data.TotalPhysMemBytes = memoryInfo.ullTotalPhys;
return data;
}
示例4: GetIpAddresses
/// <summary>
/// The get ip addresses.
/// </summary>
/// <returns>
/// </returns>
private List<string> GetIpAddresses()
{
var ips = new List<string>();
string query = "SELECT IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled=true";
ManagementObjectCollection mgtObjects = new ManagementObjectSearcher(query).Get();
foreach (
PropertyData ipaddr in
mgtObjects.Cast<ManagementObject>().Select(mo => mo.Properties["IPAddress"]).Where(ipaddr => ipaddr.IsLocal))
{
if (ipaddr.IsArray)
{
ips.AddRange((string[])ipaddr.Value);
}
else
{
ips.Add(ipaddr.Value.ToString());
}
}
return ips;
}
示例5: CollectMotherboard
private void CollectMotherboard(bool usecache)
{
if (usecache && _isMotherboardCollected)
return;
try
{
var moc = new ManagementObjectSearcher("SELECT * FROM Win32_MotherboardDevice").Get();
foreach (var o in moc.Cast<ManagementObject>())
{
PrimaryBusType = o.TryGet<string>("PrimaryBusType");
SecondaryBusType = o.TryGet<string>("SecondaryBusType");
break;
}
}
catch (Exception)
{
}
_isMotherboardCollected = true;
}
示例6: GetProcessStartAnalyticsData
private static MyProcessStartAnalytics GetProcessStartAnalyticsData()
{
MyProcessStartAnalytics data = new MyProcessStartAnalytics();
try
{
var cpus = new ManagementObjectSearcher("root\\CIMV2", "SELECT Name FROM Win32_Processor").Get();
// We're just reporting the first
var cpuName = cpus.Cast<ManagementObject>().First()["Name"].ToString();
var memoryInfo = new WinApi.MEMORYSTATUSEX();
WinApi.GlobalMemoryStatusEx(memoryInfo);
MyAdapterInfo gpu = MyVideoSettingsManager.Adapters[MyVideoSettingsManager.CurrentDeviceSettings.AdapterOrdinal];
var deviceName = gpu.Name;
data.ProcessorCount = (byte)Environment.ProcessorCount;
data.OsVersion = Environment.OSVersion.VersionString;
data.CpuInfo = cpuName;
data.OsPlatform = Environment.Is64BitOperatingSystem ? "64bit" : "32bit";
data.HasDX11 = MyDirectXHelper.IsDx11Supported();
data.GameVersion = MyFinalBuildConstants.APP_VERSION_STRING.ToString();
data.TotalPhysMemBytes = memoryInfo.ullTotalPhys;
data.GpuInfo = new MyGraphicsInfo();
data.GpuInfo.AnisotropicFiltering = MyVideoSettingsManager.CurrentGraphicsSettings.Render.AnisotropicFiltering.ToString();
data.GpuInfo.AntialiasingMode = MyVideoSettingsManager.CurrentGraphicsSettings.Render.AntialiasingMode.ToString();
data.GpuInfo.FoliageDetails = MyVideoSettingsManager.CurrentGraphicsSettings.Render.FoliageDetails.ToString();
data.GpuInfo.ShadowQuality = MyVideoSettingsManager.CurrentGraphicsSettings.Render.ShadowQuality.ToString();
data.GpuInfo.TextureQuality = MyVideoSettingsManager.CurrentGraphicsSettings.Render.TextureQuality.ToString();
data.GpuInfo.VoxelQuality = MyVideoSettingsManager.CurrentGraphicsSettings.Render.VoxelQuality.ToString();
data.GpuInfo.GrassDensityFactor = MyVideoSettingsManager.CurrentGraphicsSettings.Render.GrassDensityFactor;
data.GpuInfo.GPUModelName = gpu.DeviceName;
data.GpuInfo.GPUMemory = gpu.VRAM;
data.AudioInfo.MusicVolume = MySandboxGame.Config.MusicVolume;
data.AudioInfo.SoundVolume = MySandboxGame.Config.GameVolume;
data.AudioInfo.HudWarnings = MySandboxGame.Config.HudWarnings;
data.AudioInfo.MuteWhenNotInFocus = MySandboxGame.Config.EnableMuteWhenNotInFocus;
data.Fullscreen = MyVideoSettingsManager.CurrentDeviceSettings.WindowMode.ToString();
data.Resolution = MySandboxGame.Config.ScreenWidth.ToString() + " x " + MySandboxGame.Config.ScreenHeight.ToString();
}
catch (Exception exception)
{
MyLog.Default.WriteLine(exception);
}
return data;
}
示例7: PathIsFromVHD
public static bool PathIsFromVHD(string Location)
{
string root = Path.GetPathRoot(Location);
if (root == null)
return false;
var scope = new ManagementScope(@"root\cimv2");
scope.Connect();
var drives = new ManagementObjectSearcher(scope,
new SelectQuery(DiskStrings.LogicalDisk,
"DeviceID like '" +
root.Substring(0, root.IndexOf(':')) +
"'")).Get();
return
drives.Cast<ManagementObject>().Any(
drive =>
drive.GetRelated(DiskStrings.DiskPartition).Cast<ManagementObject>().Any(
part =>
part.GetRelated(DiskStrings.DiskDrive).Cast<ManagementObject>().Any(
device =>
new ManagementObjectSearcher(GetScope(),
new SelectQuery(DiskStrings.MountedStorage,
"Lun=" + device["SCSILogicalUnit"] +
" and PortNumber=" + device["SCSIPort"] +
" and TargetID=" + device["SCSITargetID"]))
.Get().Cast<ManagementObject>().Any())));
}