예제 #1
0
 static void CollectLocalMachine()
 {
     var computerName = SystemInformation.ComputerName;
     var wmi = new WMI(computerName);
     Computer c = GetComputerProperties(wmi);
     Console.WriteLine(c.ToJson());
 }
예제 #2
0
        /// <summary>
        /// Get a single computer's Win32 properties
        /// </summary>
        /// <param name="wmi"></param>
        /// <returns></returns>
        static Computer GetComputerProperties(WMI wmi)
        {
            var queries = new Dictionary<string, string>()
            {
                {"Baseboard","SELECT Manufacturer,Model,Product,SerialNumber FROM Win32_BaseBoard"},
                {"BIOS","SELECT Manufacturer,SerialNumber,SMBIOSBIOSVersion FROM Win32_BIOS"},
                {"DiskDrive","SELECT Model,Size,Manufacturer FROM Win32_DiskDrive"},
                {"MotherboardDevice", "SELECT PrimaryBusType,SecondaryBusType FROM Win32_MotherboardDevice"},
                //{"OperatingSystem","SELECT * FROM Win32_OperatingSystem"},
                {"PhysicalMemory","SELECT Capacity,DataWidth,FormFactor,MemoryType,Speed FROM Win32_PhysicalMemory"},
                {"Processor","SELECT Manufacturer,Name,Description,MaxClockSpeed,L2CacheSize,AddressWidth,DataWidth,NumberOfCores,NumberOfLogicalProcessors,ProcessorId FROM Win32_Processor"},
                {"VideoController","SELECT AdapterCompatibility,AdapterRAM,Name,VideoModeDescription,VideoProcessor,VideoMemoryType FROM Win32_VideoController"}
            };

            var computer = new Computer() {
                Baseboard = new Baseboard(wmi.GetQueryResult(queries["Baseboard"])),
                BIOS = new BIOS(wmi.GetQueryResult(queries["BIOS"])),
                DiskDrive = new DiskDrive(wmi.GetQueryResult(queries["DiskDrive"])),
                MotherboardDevice = new MotherboardDevice(wmi.GetQueryResult(queries["MotherboardDevice"])),
                PhysicalMemory = new PhysicalMemory(wmi.GetQueryResult(queries["PhysicalMemory"])),
                Processor = new Processor(wmi.GetQueryResult(queries["Processor"])),
                VideoController = new VideoController(wmi.GetQueryResult(queries["VideoController"]))
            };

            return computer;
        }