سؤال

I can see the value in my registry editor and the path is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography, but can't get the value with the following codes:

import _winreg

key = _winreg.OpenKey(
    _winreg.HKEY_LOCAL_MACHINE,
    "SOFTWARE\\Microsoft\\Cryptography"
    )

result = _winreg.QueryValueEx(key, "MachineGuid")

print result

I got "The system cannot find the file specified", which is confusing because it's right there.

Well, there's no problem retrieving other values with the almost exact same code:

key = _winreg.OpenKey(
    _winreg.HKEY_LOCAL_MACHINE,
    "SOFTWARE\\Microsoft\\COM3"
    )


result = _winreg.QueryValueEx(key, "BuildType")

print result

The output is: (u'Free', 1)

Which part am I doing wrong? What can I do to get this MachineGuid?

هل كانت مفيدة؟

المحلول

Your code is working fine on a 32bit Windows, if you want it to also run on a 64bit Windows, try this :

key = _winreg.OpenKey(
    _winreg.HKEY_LOCAL_MACHINE,
    "SOFTWARE\\Microsoft\\Cryptography",
    0,
    _winreg.KEY_READ | _winreg.KEY_WOW64_64KEY
)

result = _winreg.QueryValueEx(key, "MachineGuid")
print result

Reference : Change 64bit Registry from 32bit Python

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top