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


C# Management.ObjectQuery类代码示例

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


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

示例1: GetOperatingSystemInfo

 protected virtual void GetOperatingSystemInfo(string Name, string UserName, string Password)
 {
     if (string.IsNullOrEmpty(Name))
         throw new ArgumentNullException("Name");
     ManagementScope Scope = null;
     if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
     {
         ConnectionOptions Options = new ConnectionOptions();
         Options.Username = UserName;
         Options.Password = Password;
         Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2", Options);
     }
     else
     {
         Scope = new ManagementScope("\\\\" + Name + "\\root\\cimv2");
     }
     Scope.Connect();
     ObjectQuery Query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
     using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query))
     {
         using (ManagementObjectCollection Collection = Searcher.Get())
         {
             foreach (ManagementObject TempNetworkAdapter in Collection)
             {
                 if (TempNetworkAdapter.Properties["LastBootUpTime"].Value != null)
                 {
                     LastBootUpTime = ManagementDateTimeConverter.ToDateTime(TempNetworkAdapter.Properties["LastBootUpTime"].Value.ToString());
                 }
             }
         }
     }
 }
开发者ID:JKLFA,项目名称:Craig-s-Utility-Library,代码行数:32,代码来源:OperatingSystem.cs

示例2: GetPhysicalCores

        /// <summary>
        /// Gets the physcial cores and should this fail returns the Environment.ProcessorCount
        /// that can also include logical cores.
        /// </summary>
        /// <returns>core count.</returns>
        public static uint GetPhysicalCores()
        {
            try
            {
                ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
                ObjectQuery query = new ObjectQuery("SELECT NumberOfCores FROM Win32_Processor");

                ManagementObjectSearcher searcher =
                            new ManagementObjectSearcher(scope, query);

                ManagementObjectCollection queryCollection = searcher.Get();
                var enumerator = queryCollection.GetEnumerator();
                if (enumerator.MoveNext())
                {
                    ManagementObject obj = (ManagementObject)enumerator.Current;
                    return (uint)obj["NumberOfCores"];
                }
                else
                    return (uint)Environment.ProcessorCount;
            }
            // We are not very interested in throwing the exception, we might log it
            // but this carries little information as if WMI fails there is very little
            // that the we or the user can do to provide the correct information.
            catch
            {
                return (uint)Environment.ProcessorCount;
            }
        }
开发者ID:JackWangCUMT,项目名称:SCPM,代码行数:33,代码来源:Unsafe.cs

示例3: 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

示例4: 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

示例5: GetDefaultPrinterName

        public static String GetDefaultPrinterName()
        {
            {
                var query = new ObjectQuery("SELECT * FROM Win32_Printer");
                var searcher = new ManagementObjectSearcher(query);

                foreach (ManagementObject mo in searcher.Get())
                {
                    if (((bool?)mo["Default"]) ?? false)
                    {
                        string whole = mo["Name"] as string;

                        if (whole.Contains("opsprint"))
                        {
                            string[] actual;
                            actual = whole.Split('\\');
                            return actual[3];
                        }
                        else if (whole.Contains("Fax") || whole.Contains("XPS") || whole.Contains("OneNote"))
                            return "none";
                        else return whole;
                    }
                }

                return null;
            }
        }
开发者ID:kaburkett,项目名称:Windows-Password-Reminder,代码行数:27,代码来源:QueryPrinter.cs

示例6: 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

示例7: GetCOMPortsInfo

        public static List<COMPortFinder> GetCOMPortsInfo()
        {
            List<COMPortFinder> COMPortFinderList = new List<COMPortFinder>();

            ConnectionOptions options = ProcessConnection.ProcessConnectionOptions();
            ManagementScope connectionScope = ProcessConnection.ConnectionScope(Environment.MachineName, options, @"\root\CIMV2");

            ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0");
            ManagementObjectSearcher comPortSearcher = new ManagementObjectSearcher(connectionScope, objectQuery);

            using (comPortSearcher)
            {
                string caption = null;
                foreach (ManagementObject obj in comPortSearcher.Get())
                {
                    if (obj != null)
                    {
                        object captionObj = obj["Caption"];
                        if (captionObj != null)
                        {
                            caption = captionObj.ToString();
                            if (caption.Contains("(COM"))
                            {
                                COMPortFinder COMPortFinder = new COMPortFinder();
                                COMPortFinder.Name = caption.Substring(caption.LastIndexOf("(COM")).Replace("(", string.Empty).Replace(")",
                                                                     string.Empty);
                                COMPortFinder.Description = caption;
                                COMPortFinderList.Add(COMPortFinder);
                            }
                        }
                    }
                }
            }
            return COMPortFinderList;
        }
开发者ID:donnaknew,项目名称:programmingProject,代码行数:35,代码来源:COMPortFinder.cs

示例8: isAdmin

        public static bool isAdmin(string processName)
        {
            string ProcessOwner = "";
            string ProcessDomain = "";

            System.Management.ObjectQuery x = new System.Management.ObjectQuery("Select * From Win32_Process where Name='" + processName + ".exe" + "'");
            System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(x);
            foreach (System.Management.ManagementObject mo in mos.Get())
            {
                string[] s = new string[2];
                mo.InvokeMethod("GetOwner", (object[])s);
                ProcessOwner = s[0].ToString();
                ProcessDomain = s[1].ToString();
                break;
            }

            string userPath = ProcessDomain + "/" + ProcessOwner;

            using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group"))
            {
                foreach (object member in (IEnumerable)groupEntry.Invoke("Members"))
                {
                    using (DirectoryEntry memberEntry = new DirectoryEntry(member))
                    {
                        Console.WriteLine(memberEntry.Path);
                        if (memberEntry.Path.Contains(userPath))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
开发者ID:hfenigma,项目名称:d3adventure,代码行数:34,代码来源:ProcessTools.cs

示例9: DeleteShare

        public void DeleteShare(IShareDescriptor descriptor)
        {
            var wqlQuery = new ObjectQuery(string.Format(@"SELECT * from Win32_Share WHERE Name = '{0}'", descriptor.Name));

            ManagementObjectSearcher objectSearcher = new ManagementObjectSearcher(_managementClass.Scope, wqlQuery);
            ManagementObjectCollection shareObjectsCollection = objectSearcher.Get();

            if (shareObjectsCollection.Count == 0)
            {
                throw new ShareInstrumentationException(@"{0} {1}.", ExceptionMessages.Win32_ShareNotFound, descriptor.Name);
            }

            foreach (ManagementObject shareObject in shareObjectsCollection)
            {
                PropertyDataCollection outParams;
                long returnValue;

                var inParamsCollection = new List<PropertyDataObject>();
                inParamsCollection.Add(new PropertyDataObject() { Name = "Reason", Value = (uint)0 });

                _handler.Handle("Terminate", inParamsCollection, out outParams);

                returnValue = long.Parse(outParams["ReturnValue"].Value.ToString());

                if (returnValue != 0)
                {
                    throw new ShareInstrumentationException(@"{0} {1}.", ExceptionMessages.Win32_ShareFail, _errorMessageProvider.GetErrorMessage(ErrorMessageProvider.ErrorClass.Win32_Share, returnValue));
                }
            }
        }
开发者ID:danni95,项目名称:Core,代码行数:30,代码来源:ShareInstrumentation.cs

示例10: DisplayRam

        private void DisplayRam(object sender, EventArgs e)
        {
            //In thong so trong tabMemry
            ManagementScope oMs = new ManagementScope();
            ObjectQuery oQuery = new ObjectQuery("SELECT Capacity FROM Win32_PhysicalMemory");
            ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
            ManagementObjectCollection oCollection = oSearcher.Get();

            long MemSize = 0;
            long mCap = 0;
            long FreePhysicalMemory = 0;

            // In case more than one Memory sticks are installed
            foreach (ManagementObject obj in oCollection)
            {
                mCap = Convert.ToInt64(obj["Capacity"]);
                MemSize += mCap;
            }
            MemSize = (MemSize / 1024) / 1024;
            txtRam.Text = MemSize.ToString() + "  MB";

            // Get info RAM availble
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_OperatingSystem");
            foreach (ManagementObject tmp in searcher.Get())
            {
                FreePhysicalMemory = Convert.ToInt64(tmp["FreePhysicalMemory"]);
            }
            FreePhysicalMemory = (FreePhysicalMemory) / 1024;
            txtRamAvai.Text = FreePhysicalMemory.ToString() + "  MB";
        }
开发者ID:neittien0110,项目名称:Project-2,代码行数:30,代码来源:FormCPU-T.cs

示例11: getComputerInfos

        public static String[] getComputerInfos(string computername)
        {
            String[] computerInfos = new String[2];

            ConnectionOptions connOptions = new ConnectionOptions();
            ObjectGetOptions objectGetOptions = new ObjectGetOptions();
            ManagementPath managementPath = new ManagementPath("Win32_Process");

            //To use caller credential
            connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", computername), connOptions);
            manScope.Connect();
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(manScope, query);
            ManagementObjectCollection queryCollection = searcher.Get();

            foreach (ManagementObject m in queryCollection){

                computerInfos[0] = Convert.ToString(m["Caption"]);
                computerInfos[1] = Convert.ToString(m["Status"]);

            }

            return computerInfos;
        }
开发者ID:banctilrobitaille,项目名称:RemoteScriptLauncher,代码行数:26,代码来源:CommUtility.cs

示例12: getUID

        public static String getUID()
        {
            try
            {
                ManagementScope theScope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
                StringBuilder theQueryBuilder = new StringBuilder();
                theQueryBuilder.Append("SELECT MACAddress FROM Win32_NetworkAdapter");
                ObjectQuery theQuery = new ObjectQuery(theQueryBuilder.ToString());
                ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
                ManagementObjectCollection theCollectionOfResults = theSearcher.Get();

                foreach (ManagementObject theCurrentObject in theCollectionOfResults)
                {
                    if (theCurrentObject != null && theCurrentObject["MACAddress"] != null)
                    {
                        return theCurrentObject["MACAddress"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                return "undefined";
            }
            return "undefined";
        }
开发者ID:peppy,项目名称:sgl4cs,代码行数:25,代码来源:ErrorReporter.cs

示例13: UpdateCameraList

        /// <summary>
        /// Updates the list of cameras
        /// </summary>
        /// <returns>The list of cameras</returns>
        public static ManagementObjectCollection UpdateCameraList()
        {
                    
            //Searches for the device using its name
            ObjectQuery oq = new System.Management.ObjectQuery("select * from Win32_PnPEntity where Name='NaturalPoint OptiTrack V100'");
            ManagementObjectSearcher query = new ManagementObjectSearcher(oq);
            ManagementObjectCollection queryCollection = query.Get();
            /*
            Console.WriteLine();
            Console.WriteLine("Number of Cameras : " + queryCollection.Count);
            if (queryCollection.Count > 0)
            {
                foreach (ManagementObject mo in queryCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("USB Camera");

                    

                    foreach (PropertyData propertyData in mo.Properties)
                    {
                       

                        Console.WriteLine("Property Name = " + propertyData.Name);

                        Console.WriteLine("Property Value = " + propertyData.Value);

                    }
                    
                }
            }
            */
            return queryCollection;
        }
开发者ID:matalangilbert,项目名称:stromohab-2008,代码行数:38,代码来源:WMIDevices.cs

示例14: 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

示例15: GetFilesWithExtension

 /// <summary>
 /// Gets a list of files on the machine with a specific extension
 /// </summary>
 /// <param name="Computer">Computer to search</param>
 /// <param name="UserName">User name (if not local)</param>
 /// <param name="Password">Password (if not local)</param>
 /// <param name="Extension">File extension to look for</param>
 /// <returns>List of files that are found to have the specified extension</returns>
 public static IEnumerable<string> GetFilesWithExtension(string Computer, string UserName, string Password, string Extension)
 {
     Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(Computer), "Computer");
     Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(Extension), "Extension");
     List<string> Files = new List<string>();
     ManagementScope Scope = null;
     if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
     {
         ConnectionOptions Options = new ConnectionOptions();
         Options.Username = UserName;
         Options.Password = Password;
         Scope = new ManagementScope("\\\\" + Computer + "\\root\\cimv2", Options);
     }
     else
     {
         Scope = new ManagementScope("\\\\" + Computer + "\\root\\cimv2");
     }
     Scope.Connect();
     ObjectQuery Query = new ObjectQuery("SELECT * FROM CIM_DataFile where Extension='" + Extension + "'");
     using (ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query))
     {
         using (ManagementObjectCollection Collection = Searcher.Get())
         {
             foreach (ManagementObject TempBIOS in Collection)
             {
                 Files.Add(TempBIOS.Properties["Drive"].Value.ToString()+TempBIOS.Properties["Path"].Value.ToString()+TempBIOS.Properties["FileName"].Value.ToString());
             }
         }
     }
     return Files;
 }
开发者ID:kaytie,项目名称:Craig-s-Utility-Library,代码行数:39,代码来源:Files.cs


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