如何检索WMI数据,例如C#程序UUID? [英] How to retrieve WMI data such as UUID from a C# program?

查看:1386
本文介绍了如何检索WMI数据,例如C#程序UUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要检索系统的UUID我们有WMIC命令行实用程序的选项

To retrieve system's UUID we have the option of WMIC command-line utility

wmic csproduct get uuid

如何使用C或C#程序或使用检索系统相同UUID的.dll?

How to retrieve the same uuid from a system using C or C# program or using .dll?

推荐答案

您可以从的 Win32_ComputerSystemProduct WMI类,试试这个样本。

You can get the Universally unique identifier (UUID) value from the Win32_ComputerSystemProduct WMI class, try this sample.

using System;
using System.Collections.Generic;
using System.Management;
using System.Text;

namespace GetWMI_Info
{
    class Program
    {

        static void Main(string[] args)
        {
            try
            {
                string ComputerName = "localhost";
                ManagementScope Scope;                
                Scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", ComputerName), null);
                Scope.Connect();
                ObjectQuery Query = new ObjectQuery("SELECT UUID FROM Win32_ComputerSystemProduct");
                ManagementObjectSearcher Searcher = new ManagementObjectSearcher(Scope, Query);

                foreach (ManagementObject WmiObject in Searcher.Get())
                {
                    Console.WriteLine("{0,-35} {1,-40}","UUID",WmiObject["UUID"]);// String                     
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("Exception {0} Trace {1}",e.Message,e.StackTrace));
            }
            Console.WriteLine("Press Enter to exit");
            Console.Read();
        }
    }
}

这篇关于如何检索WMI数据,例如C#程序UUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆