【问题标题】:how to get Device UUID using C# [duplicate]如何使用 C# 获取设备 UUID [重复]
【发布时间】:2021-08-08 09:39:38
【问题描述】:

我想使用 C# 获取设备 UUID。我需要的 ID 可以使用wmic csproduct get uuid cmd 命令获取。我尝试在 C# cmd 进程中运行此命令,但它没有提供唯一的 UUID 作为输出。它提供所有 cmd 文本作为输出。那么,我如何在 C# 中获取设备 UUID。我使用 .net 框架 4.7.2。

【问题讨论】:

    标签: c# .net uuid


    【解决方案1】:

    您可以应用正则表达式来过滤来自 wmic 的输出:

    private string GetUuid()
    {
        try
        {
            var proc = Process.Start(new ProcessStartInfo
            {
                FileName = "wmic.exe",
                Arguments = "csproduct get uuid",
                RedirectStandardOutput = true
            });
            if (proc != null)
            {
                string output = proc.StandardOutput.ReadToEnd();
                // Search for UUID string
                var match = System.Text.RegularExpressions.Regex.Match(output, @"[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}");
                if (match.Success) { return match.Value; }
            }
        }
        catch { }  // Your exception handling
        return null;  // Or string.Empty
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      • 2011-06-24
      • 2015-02-12
      相关资源
      最近更新 更多