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


C# ManagementObjectSearcher.Dispose方法代码示例

本文整理汇总了C#中System.Management.ManagementObjectSearcher.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.Dispose方法的具体用法?C# ManagementObjectSearcher.Dispose怎么用?C# ManagementObjectSearcher.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.ManagementObjectSearcher的用法示例。


在下文中一共展示了ManagementObjectSearcher.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBrightnessLevel

        /// <summary>
        ///     Query the brightness setting of the display.
        /// </summary>
        internal static int GetBrightnessLevel()
        {
            try
            {
                var s = new ManagementScope("root\\WMI");
                var q = new SelectQuery("WmiMonitorBrightness");
                var mos = new ManagementObjectSearcher(s, q);
                var moc = mos.Get();

                foreach (var managementBaseObject in moc)
                {
                    foreach (var o in managementBaseObject.Properties)
                    {
                        if (o.Name == "CurrentBrightness")
                            return Convert.ToInt32(o.Value);
                    }
                }

                moc.Dispose();
                mos.Dispose();
            }
            catch (ManagementException ex)
            {
                // ignore
                // it is possible that laptop lid is closed, and using external monitor
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return 0;
        }
开发者ID:navhaxs,项目名称:BrightnessTray,代码行数:36,代码来源:WmiFunctions.cs

示例2: GetHotfixDetails

        public static List<EntHotfixes> GetHotfixDetails(ManagementScope scope)
        {
            _logger.Info("Collecting hotfix for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntHotfixes> lstHotfix = new List<EntHotfixes>();

            try
            {
                query = new ObjectQuery("Select * from Win32_QuickFixEngineering");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstHotfix.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstHotfix.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (System.Exception e)
            {
                _logger.Error("Exception is hotfix collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstHotfix;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:Hotfix.cs

示例3: GetPartialStuffInfo

        public static List<PropertyData> GetPartialStuffInfo(string stuff, string[] targets)
        {
            List<PropertyData> hd = new List<PropertyData>();
            try
            {
                StringBuilder sb = new StringBuilder(" SELECT ");
                foreach (string t in targets)
                {
                    sb.Append(t).Append("  ");
                }
                sb.Append("  FROM ").Append(stuff);

                ManagementObjectSearcher searcher = new ManagementObjectSearcher(sb.ToString());
                ManagementObjectCollection information = searcher.Get();
                foreach (ManagementObject obj in information)
                {
                    // Retrieving the properties (columns)
                    // Writing column name then its value

                    foreach (PropertyData data in obj.Properties)
                    {
                        Console.WriteLine("{0} = {1}", data.Name, data.Value);
                        hd.Add(data);
                    }
                }
                searcher.Dispose();
            }
            catch (Exception e)
            {
                return null;
            }
            return hd;
        }
开发者ID:harryho,项目名称:demo-fx-trading-platform-prototype,代码行数:33,代码来源:SysUtil.cs

示例4: ObjectQuery

        public static List<EntStartUp>GetStartUpDetails(ManagementScope scope)
        {
            _logger.Info("Collecting startup details for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntStartUp> lstStartUp = new List<EntStartUp>();

            try
            {
                query = new ObjectQuery("select * from Win32_StartupCommand where User != '.DEFAULT' and User != 'NT AUTHORITY\\\\SYSTEM'");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstStartUp.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstStartUp.Add(FillDetails(obj));
                    obj.Dispose();
                }

            }
            catch (System.Exception e)
            {
                _logger.Error("Exception in startup collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstStartUp;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:32,代码来源:StartUp.cs

示例5: ObjectQuery

        public static List<EntUserGroups>GetUserGroupDetails(ManagementScope scope)
        {
            _scope = scope;
            _logger.Info("Collecting user groups details for machine " + _scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntUserGroups> lstUserGroup = new List<EntUserGroups>();

            try
            {
                query = new ObjectQuery("Select * from Win32_Group");
                searcher = new ManagementObjectSearcher(_scope, query);
                objects = searcher.Get();
                lstUserGroup.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstUserGroup.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (System.Exception e)
            {
                _logger.Error("Exception in user groups collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
                _scope = null;

            }
            return lstUserGroup;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:34,代码来源:UserGroups.cs

示例6: stopidle

        static void stopidle()
        {
            //taken from idlemaster project by jshackles.
            try
            {
                var username = WindowsIdentity.GetCurrent().Name;
                foreach (var process in Process.GetProcessesByName("steam-idle"))
                {
                    var searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ProcessID = " + process.Id);
                    var processList = searcher.Get();

                    foreach (ManagementObject obj in processList)
                    {
                        var argList = new string[] { string.Empty, string.Empty };
                        var returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
                        if (returnVal == 0)
                        {
                            if (argList[1] + "\\" + argList[0] == username)
                            {
                                process.Kill();
                            }
                        }
                    }
                    searcher.Dispose();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error while stopping idle, please shut down all steam-idle.exe processes by hand from task manager.");
            }
        }
开发者ID:ardaozkal,项目名称:steam_time_idler,代码行数:31,代码来源:Form1.cs

示例7: GetMultimediaDetails

        public static List<EntMultimedia> GetMultimediaDetails(ManagementScope scope)
        {
            _logger.Info("Collecting monitor details for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntMultimedia> lstMultimedia = new List<EntMultimedia>();

            try
            {
                query = new ObjectQuery("Select * from Win32_SoundDevice");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstMultimedia.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstMultimedia.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (System.Exception e)
            {
                _logger.Error("Exception is multimedia collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstMultimedia;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:Multimedia.cs

示例8: GetOSDetails

        public static List<EntOS> GetOSDetails(ManagementScope scope)
        {
            _logger.Info("Collecting OS details for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntOS> lstOS = new List<EntOS>();

            try
            {
                query = new ObjectQuery("Select * from Win32_OperatingSystem");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstOS.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstOS.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (System.Exception e)
            {
                _logger.Error("Exception in OS collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstOS;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:OS.cs

示例9: ObjectQuery

        public static List<EntDisk>GetDiskDetails(ManagementScope scope)
        {
            _logger.Info("Collecting disk details for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntDisk> lstDisk = new List<EntDisk>();

            try
            {
                query = new ObjectQuery("Select * from Win32_DiskDrive");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstDisk.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstDisk.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (Exception e)
            {
                _logger.Error("Exception is disk collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstDisk;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:Disk.cs

示例10: ObjectQuery

        public static List<EntEnvironmentVars>GetEnvironmentVarDetails(ManagementScope scope)
        {
            _logger.Info("Collecting Environment variable for machine " + scope.Path.Server);

            ObjectQuery query = null;
            ManagementObjectSearcher searcher = null;
            ManagementObjectCollection objects = null;
            List<EntEnvironmentVars> lstEnvVars = new List<EntEnvironmentVars>();

            try
            {
                query = new ObjectQuery("Select * from Win32_Environment");
                searcher = new ManagementObjectSearcher(scope, query);
                objects = searcher.Get();
                lstEnvVars.Capacity = objects.Count;
                foreach (ManagementBaseObject obj in objects)
                {
                    lstEnvVars.Add(FillDetails(obj));
                    obj.Dispose();
                }
            }
            catch (System.Exception e)
            {
                _logger.Error("Exception is Environment var collection " + e.Message);
            }
            finally
            {
                searcher.Dispose();
            }
            return lstEnvVars;
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:31,代码来源:EnvironmentVar.cs

示例11: refreshProcess

        void refreshProcess()
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Process");
            foreach (ManagementObject manObj in searcher.Get())
            {
                if (!IsExistInfoUnit(array, Convert.ToInt32(manObj["ProcessID"])))
                {
                    ProcessInfoUnit unitInfo = new ProcessInfoUnit();
                    unitInfo.ProcessID = int.Parse(manObj["ProcessID"].ToString());

                    if (manObj["Caption"] != null)
                        unitInfo.Caption = manObj["Caption"].ToString();

                    if (manObj["CommandLine"] != null)
                        unitInfo.CommandLine = manObj["CommandLine"].ToString();

                    if (manObj["CreationDate"] != null)
                    {
                        string date = manObj["CreationDate"].ToString();
                        date = date.Substring(0, 4) + "-" + date.Substring(4, 2) + "-" + date.Substring(6, 2) + " " + date.Substring(8, 2) + ":" + date.Substring(10, 2) + ":" + date.Substring(12, 2);
                        unitInfo.CreationDate = DateTime.Parse(date);
                    }

                    array.Add(unitInfo);
                }
            }
            searcher.Dispose();
        }
开发者ID:wykoooo,项目名称:copy-dotnet-library,代码行数:28,代码来源:Processes.cs

示例12: AdapterConfiguration

        /*
                        /// <summary>
                        ///
                        /// </summary>
                        internal static void AdapterConfiguration()
                        {
                                    // http://msdn.microsoft.com/en-us/library/aa394217(v=VS.85).aspx

                        }
                        */
        /// <summary>
        /// 
        /// </summary>
        internal static void EnableAdapters()
        {
            Log.AppendHeader( logfile, "Network Configuration" );

                                    ManagementObjectSearcher searcher = null;

                                    try
                                    {

                                                searcher = new ManagementObjectSearcher( "Select * from Win32_NetworkAdapter" );

                                                foreach ( ManagementObject mo in searcher.Get() )
                                                {

                                                            try
                                                            {

                                                                        // Works for Vista and later
                                                                        // http://msdn.microsoft.com/en-us/library/aa390385(v=VS.85).aspx

                                                                        UInt32 success = (UInt32)mo.InvokeMethod( "Enable", null );

                                                                        if ( success == 0 )
                                                                                    Display.UpdateStatus( mo["Caption"].ToString() + " enabled" );

                                                            }
                                                            catch ( Exception )
                                                            {

                                                            }
                                                            finally
                                                            {

                                                            }

                                                }

                                    }
                                    catch ( Exception )
                                    {

                                    }
                                    finally
                                    {

                                                // Cleanup
                                                if ( searcher != null )
                                                {

                                                            searcher.Dispose();
                                                            searcher = null;

                                                }

                                    }
        }
开发者ID:AndrewBarfield,项目名称:Barfield-Cleaner,代码行数:69,代码来源:Network.cs

示例13: GetCpuCore

 public static string GetCpuCore()
 {
     ManagementClass mc = new ManagementClass("Win32_Processor");
     ManagementObjectCollection cpus = mc.GetInstances();
     string count = null;
     string co = null;
     ManagementObjectSearcher mySearch = new ManagementObjectSearcher("select * from Win32_Processor");
     foreach (ManagementObject mo in mySearch.Get())
     {
         count = mo.Properties["NumberOfCores"].Value.ToString();
     }
     mc.Dispose();
     mySearch.Dispose();
     return count;
 }
开发者ID:CatMsg,项目名称:Project,代码行数:15,代码来源:GetWare.cs

示例14: WMIForm_Load

 private void WMIForm_Load(object sender, EventArgs e)
 {
     SelectQuery sq = new SelectQuery("Win32_OperatingSystem");
     ManagementObjectSearcher mos = new ManagementObjectSearcher(sq);
     ManagementObjectCollection moc = mos.Get();
     foreach (ManagementObject mo in moc)
     {
         foreach (PropertyData pd in mo.Properties)
         {
             richTextBox1.AppendText(pd.Name + ":" + pd.Value + "\n");
         }
     }
     moc.Dispose();
     mos.Dispose();
     sq = null;
 }
开发者ID:dawndiy,项目名称:DawnBrowser,代码行数:16,代码来源:WMIForm.cs

示例15: Lookup

        public static ArgumentTokenCollection Lookup(int processId)
        {
            string wmiQuery = string.Format("SELECT CommandLine FROM Win32_Process WHERE ProcessId = {0}", processId);
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
            ManagementObjectCollection retObjectCollection = searcher.Get();

            try
            {
                string commandLine = string.Empty;

                if (retObjectCollection.Count == 0 || retObjectCollection.Count > 1)
                {
                    return ArgumentTokenCollection.Empty;
                }

                using (var enumerator = retObjectCollection.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        commandLine = enumerator.Current["CommandLine"].ToString();
                    }
                }

                var parser = new ArgumentParser(commandLine);
                return parser.GetArguments();
            }
            finally
            {
                if (searcher != null)
                {
                    searcher.Dispose();
                }

                if (retObjectCollection != null)
                {
                    retObjectCollection.Dispose();
                }
            }

            //foreach (ManagementObject retObject in retObjectCollection)
            //{
            //    return retObject["CommandLine"].ToString();
            //}
        }
开发者ID:modulexcite,项目名称:vs-restart,代码行数:44,代码来源:ProcessArgumentsProvider.cs


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