streda, 13 november 2019 11:39 Written by 3066 times
Rate this item
(0 votes)

C# - System.Management WqlObjectQuery Examples

Ukážeme si ako jednoducho vyčitať rozne informacie o pc použitím System.Management WqlObjectQuery

Príklad v c#:

using System;
using System.Management;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            WqlObjectQuery wqlQueryComputerSystemProduct =
                   new WqlObjectQuery("SELECT * FROM Win32_ComputerSystemProduct");
            ManagementObjectSearcher searcher =
                new ManagementObjectSearcher(wqlQueryComputerSystemProduct);


            foreach (ManagementObject product in searcher.Get())
            {
                Console.WriteLine($"identifyingNumber : {product["IdentifyingNumber"]}");
                Console.WriteLine($"name : {product["Name"]}");
            }


            WqlObjectQuery wqlQueryComputerSystem =
                new WqlObjectQuery("SELECT * FROM Win32_ComputerSystem");


            ManagementObjectSearcher searcher2 = new ManagementObjectSearcher(wqlQueryComputerSystem);

            foreach (ManagementObject item in searcher2.Get())
            {
                Console.WriteLine($"ramCapacity : {item["TotalPhysicalMemory"]}");
            }

            WqlObjectQuery wqlQueryOperatingSystem =
               new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");

            ManagementObjectSearcher searcher3 = new ManagementObjectSearcher(wqlQueryOperatingSystem);

            foreach (ManagementObject manObject in searcher3.Get())
            {
                Console.WriteLine($"Name : {manObject["name"]}");
                Console.WriteLine($"Version : { manObject["version"]}");
                Console.WriteLine($"Manufacturer : { manObject["Manufacturer"]}");
                Console.WriteLine($"Computer Name : {manObject["csname"]}");
                Console.WriteLine($"Windows Directory : { manObject["WindowsDirectory"]}");
            }

            Console.ReadKey();
        }
    }
}
Last modified on streda, 13 november 2019 11:54
Ing.Jaroslav Vadel

Som zakladateľom www.projectik.eu.

Hrám sa na programátora, ktorý ovláda:

c#,cpp,java,unity3d,php,html,NI testand,NI Vision Builder,Cognex In-Sight,NI LabView

"Naprogramovať program, ktorý funguje vie každy. Ale to, že program funguje ešte neznamena, že je napísany správne "

Website: www.projectik.eu