简体   繁体   中英

Using winreg for getting GPU details

I'm using winreg in python 3.4 to get windows registry values. I already set up a system to get CPU informations (cpu name, max frequency, etc.) and i'm trying to adapt it to get GPU informations. The only problem is that the key that contain the GPU values is stored there: SYSTEM\\CurrentControlSet\\Control\\Video{D1B33FF8-E663-44A7-9C71-2CE551F6C0EE}\\0000

So here's my code line to get to the GPU "directory":

self.connection = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
self.subkey = winreg.OpenKey(self.connection, "SYSTEM\CurrentControlSet\Control\Video\{D1B33FF8-E663-44A7-9C71-2CE551F6C0EE}\0000")

But I get this error: "OpenKey() argument 2 must be str without null characters or None, not str" So my question is: How can I use null characters in the path ? Thanks a lot, Julien.

The backslash characters in the string are used as escape sequences in Python.

The easiest way to use them as regular characters is to use a r-string:

self.subkey = winreg.OpenKey(self.connection, r"SYSTEM\CurrentControlSet\Control\Video\{D1B33FF8-E663-44A7-9C71-2CE551F6C0EE}\0000")

That is use r"..." instead of just "..." . That way the backslash character is not used as an escape character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM