windows - 宏碁显示器序列号

标签 windows python-3.x inventory edid

我正在尝试通过 Windows 注册表获取 Acer 显示器的序列号。 我正在使用 Python 3 中的以下代码解析注册表:

import winreg
from winreg import HKEY_LOCAL_MACHINE

subKey = "SYSTEM\CurrentControlSet\Enum\DISPLAY"
k = winreg.OpenKey(HKEY_LOCAL_MACHINE, subKey)

with winreg.OpenKey(HKEY_LOCAL_MACHINE, subKey) as k:
    """"
        Open the key 'HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY'
        to get the info of all connected monitors
    """
    i = 0
    while True:
        try:
            with winreg.OpenKey(k, winreg.EnumKey(k, i)) as sk:
                j = 0
                while True:
                    try:
                        with winreg.OpenKey(sk, winreg.EnumKey(sk, j)) as ssk:
                            l = 0
                            while True:
                                try:
                                    if (winreg.EnumKey(ssk, l) == "Control"):
                                        try:
                                            with winreg.OpenKey(ssk, "Device Parameters") as sssk:
                                                strEDID = str(winreg.EnumValue(sssk, 0)[1])
                                                try:
                                                    modelo = strEDID[strEDID.index("\\x00\\x00\\x00\\xfc") + len("\\x00\\x00\\x00\\xfc\\x00"):].split("\\")[0]
                                                    serie = strEDID[strEDID.index("\\x00\\x00\\x00\\xff") + len("\\x00\\x00\\x00\\xff\\x00"):].split("\\")[0]
                                                except:
                                                    modelo = "Not Found"
                                                    serie = "Not Found"

                                                print ("Modelo:", modelo)
                                                print ("Serie:", serie, "\n")

                                                fo = open("salTest.txt", "a")
                                                fo.write(modelo + "\n")
                                                fo.write(serie + "\n\n")
                                                fo.close()

                                        except OSError:
                                            print ("Error")
                                        break
                                    else:
                                        l += 1
                                except OSError:
                                    break
                        j += 1
                    except OSError:
                        break
            i += 1
        except OSError:
            break

结果我在 cmd 窗口中得到如下输出:

Modelo: AL1716
Serie: L4802017396L

问题是“Serie”不是真正的序列号(Acer 显示器序列号有 22 个字符,看起来像“ETL480201781700F4B396L”)
有一种方法可以使用“Serie”和也可识别显示器的 SNID 来构建真实的序列号。
以下是两台 Acer 显示器的示例:

S/N ORIGINAL:           ETL48020178170 (0F4B)396L   |       # ETL480201781700F4B396L
------------------------------------------------------------------------------------
SNID:                             8170 (0F4B)=03915 |   39  # 81700391539
S/N FROM SCRIPT:          L4802017           396L   |       # L4802017396L



S/N ORIGINAL:           ETL48020178170 (2C98)396L   |       # ETL480201781702C98396L
------------------------------------------------------------------------------------
SNID:                             8170 (2C98)=11416 |   39  # 81701141639
S/N FROM SCRIPT:          L4802017           396L   |       # L4802017396L

有人知道如何获取此信息吗?

谢谢!

最佳答案

Acer 在 000000ff00 标志后提供序列号,但序列号的中间部分隐藏在 EDID 字符串的前面。

例如,我们的 EDID 字符串如下所示:

00ffffffffffff0004723a03c4fe603324170103682f1e78ca9265a655559f280d5054bfef80714f8140818081c0810095000101010126399030621a274068b03600da281100001c000000fd00374c1e5011000a202020202020000000fc0042323236574c0a202020202020000000ff004c58565341303031383531300a007b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

我们想要的序列号是这样的: LXVSA0013360FEC48510

序列号LXVSA001的前8个字符被编码为紧随“000000ff00”标志之后的十六进制字符串。

序列号 8510 的最后 4 个字符在前 8 个字符之后被编码为十六进制字符串。

000000ff00 4c|58|56|53|41|30|30|31|38|35|31|30|0a|        <-- EDID (hex)
           L  X  V  S  A  O  0  1  8  5  1  0 (linefeed)  <-- ascii
          (^^^^ first part ^^^^^^)(last part)

现在,棘手的中间部分 3360fec4 在 EDID 中被编码为 4 个字符串。

33 位于位置 30 60 位于位置 28 fe 位于位置 26 c4 位于位置 24

00ffffffffffff0004723a03
position 24 -> c4
position 26 -> fe
position 28 -> 60
position 30 -> 33
24170103682f1e78ca9265a655559f etc

当我说“位置”时,我的意思是将 EDID 字符串作为数组,索引从 0 开始。 它们很难找到,因为它们的顺序相反。

在您的示例中,序列号 81700F4B 的缺失部分应作为 4 个单独的 2 个字符串位于 idid 字符串的位置 30、28、26 和 24 处。我无法测试这一点,因为我没有完整的 IDID。

关于windows - 宏碁显示器序列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27990788/

相关文章:

python-3.x - PyQt,QThread : GUI freeze with large amount of SIGNAL from another thread (QListWidget massive update)

c# - 绘制矩形多维数组

json - Ansible 中的自定义动态库存脚本/插件

python - cx_freeze : How do I resolve conflicts caused by multiple . 同名dylib文件

javascript - Python Flask 在 javascript 文件中使用 config.py 中的变量

c - 库存计划,可能的边界值问题?

windows - 使用 Share-Delete 打开文件是否允许其他人写入?

python - Windows 上的 subprocess.call 没有启动第二个文件

CreateProcess 和 lpCommandLine 生命周期

Windows 10 更新后 MySql 5.7 服务无法启动