当前位置: 首页>>代码示例>>C#>>正文


C# ManagementObjectSearcher.Cast方法代码示例

本文整理汇总了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;
        }
开发者ID:GT-Deck,项目名称:StarMade-Remote-Start-Server,代码行数:11,代码来源:serverManager.cs

示例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();
            }
        }
开发者ID:kellysolow,项目名称:simple-semantic-web-editor,代码行数:18,代码来源:Fuseki.cs

示例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;
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:22,代码来源:MyAnalyticsHelper.cs

示例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;
        }
开发者ID:seif,项目名称:papercut-web,代码行数:28,代码来源:OptionsWindow.xaml.cs

示例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;
		}
开发者ID:cssack,项目名称:CsGlobals,代码行数:22,代码来源:CsgComputerMainBoard.cs

示例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;
        }
开发者ID:liiir1985,项目名称:SpaceEngineers,代码行数:46,代码来源:MyAnalyticsHelper.cs

示例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())));
 }
开发者ID:virmitio,项目名称:TempRepo,代码行数:26,代码来源:Utility.cs


注:本文中的System.Management.ManagementObjectSearcher.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。