zoukankan      html  css  js  c++  java
  • c#获取计算机信息

    ManagementObjectSearcher 类

    基于指定的查询检索管理对象的集合。此类是用于检索管理信息的较为常用的入口点之一。例如,它可以用于枚举系统中的所有磁盘驱动器、网络适配器、进程及更多管理对象,或者用于查询所有处于活动状态的网络连接以及暂停的服务等。在实例化之后,此类的实例可以接受在 ObjectQuery 或其派生类中表示的 WMI 查询作为输入,并且还可以选择接受一个 ManagementScope(表示执行查询时所在的 WMI 命名空间)。它还可以接受 EnumerationOptions 中的其他高级选项。当调用此对象的 Get 方法时,ManagementObjectSearcher 在指定的范围内执行给定的查询,并返回与 ManagementObjectCollection 中的查询匹配的管理对象的集合。



    using System;
    using System.Management;
    public class RemoteConnect
    {
        public static void Main()
        {
            /*// Build an options object for the remote connection
            //   if you plan to connect to the remote
            //   computer with a different user name
            //   and password than the one you are currently using
             
                 ConnectionOptions options =
                     new ConnectionOptions();
                    
                 // and then set the options.Username and
                 // options.Password properties to the correct values
                 // and also set
                 // options.Authority = "ntdlmdomain:DOMAIN";
                 // and replace DOMAIN with the remote computer's
                 // domain.  You can also use kerberose instead
                 // of ntdlmdomain.
            */

            // Make a connection to a remote computer.
            // Replace the "FullComputerName" section of the
            // string "\\\\FullComputerName\\root\\cimv2" with
            // the full computer name or IP address of the
            // remote computer.
            ManagementScope scope =
                new ManagementScope(
                "\\\\FullComputerName\\root\\cimv2");
            scope.Connect();

            // Use this code if you are connecting with a
            // different user name and password:
            //
            // ManagementScope scope =
            //    new ManagementScope(
            //        "\\\\FullComputerName\\root\\cimv2", options);
            // scope.Connect();

            //Query system for Operating System information
            ObjectQuery query = new ObjectQuery(
                "SELECT * FROM Win32_OperatingSystem");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(scope,query);

            ManagementObjectCollection queryCollection = searcher.Get();
            foreach ( ManagementObject m in queryCollection)
            {
                // Display the remote computer information
                Console.WriteLine("Computer Name : {0}",
                    m["csname"]);
                Console.WriteLine("Windows Directory : {0}",
                    m["WindowsDirectory"]);
                Console.WriteLine("Operating System: {0}", 
                    m["Caption"]);
                Console.WriteLine("Version: {0}", m["Version"]);
                Console.WriteLine("Manufacturer : {0}",
                    m["Manufacturer"]);
            }
        }
    }
    参数集合
    Win32_1394Controller
    Win32_1394ControllerDevice
    Win32_Account
    Win32_AccountSID
    Win32_ACE
    Win32_ActionCheck
    Win32_AllocatedResource
    Win32_ApplicationCommandLine
    Win32_ApplicationService
    Win32_AssociatedBattery
    Win32_AssociatedProcessorMemory
    Win32_BaseBoard
    Win32_BaseService
    Win32_Battery
    Win32_Binary
    Win32_BindImageAction
    Win32_BIOS
    Win32_BootConfiguration
    Win32_Bus
    Win32_CacheMemory
    Win32_CDROMDrive
    Win32_CheckCheck
    Win32_CIMLogicalDeviceCIMDataFile
    Win32_ClassicCOMApplic

    微软BI技术交流群:316744959 武汉NET技术群:961108969 NET技术群:21386099 本人具有丰富的系统开发经验,承接系统开发,小程序,NET系统开发,BI开发,有需求联系微信手机:15010195887
  • 相关阅读:
    【全网最全的博客美化系列教程】文章总目录
    不要再被骗了------QQ盗号原理大揭秘
    努力的孩子运气不会太差,跌宕的人生定当更加精彩
    我的七条人生哲理以及个人学习方法总结
    博客园自定义页面风格设计 后续篇(页面设计模式及代码高亮 鼠标点击效果升级)
    【资料分享】500篇干货解读人工智能新时代
    我的大一生活以及在博客园写博客的这一年
    博客园自定义页面风格设计
    ACM退役记&&回忆录
    留言板
  • 原文地址:https://www.cnblogs.com/Impulse/p/1239159.html
Copyright © 2011-2022 走看看