Win32_PhysicalMedia 为非管理员用户返回不同的序列号 [英] Win32_PhysicalMedia returns different serial number for non-admin user

查看:43
本文介绍了Win32_PhysicalMedia 为非管理员用户返回不同的序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下查询来获取硬盘序列号.

I've used the following query to fetch hard disk serial number.

ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");

它为管理员用户和非管理员用户返回不同的序列号如下:

It returns different serial number for admin user and non-admin user as follows:

管理员 - WD-WCAYUS426947非管理员 - 2020202057202d44435759415355323439363734

admin - WD-WCAYUS426947 non-admin - 2020202057202d44435759415355323439363734

当试图将非管理员序列号转换为十六进制到字符的转换器时,它给出了W -DCWYASU249674,这实际上是每 2 个字符进行一次字符交换.

When tried to put the non-admin serial into hex to char converter it gave W -DCWYASU249674, which is actually a character swap on every 2 characters.

有没有办法在不修改非十六进制格式的情况下获取正确的序列号?

Any idea to fetch the correct serial without manupulating the un-hexed format please?

推荐答案

如评论中所贴:这似乎是 Windows 中未解决的错误,尽管 微软知道这一点.

As posted in the comments: This seems to be an unsolved bug in Windows, although Microsoft knows about it.

解决它的方法是转换十六进制字符串并交换数字,我为您编写了一个方法,您可以根据需要随意编辑它:

The way to solve it is to convert the hex string and swap the numbers, I wrote a method that does this for you, feel free to edit it to your needs:

    public static string ConvertAndSwapHex(string hex)
    {
        hex = hex.Replace("-", "");
        byte[] raw = new byte[hex.Length / 2];
        for (int i = 0; i < raw.Length; i++)
        {
            int j = i;
            if (j != 0)
            {
                j = (j % 2 == 1 ? j-1 : j+1);
            }
            raw[j] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
        }
        return System.Text.Encoding.UTF8.GetString(raw).Trim(' ', '\t', '\0');
    }

这篇关于Win32_PhysicalMedia 为非管理员用户返回不同的序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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