Read registry problem

Mark Hammond mhammond at
Thu Aug 8 01:35:55 CEST 2002

Rémi wrote:
> I want to read a registry the next lines works well:
>    reg = OpenKey(HKEY_CLASSES_ROOT,"")
>    exefile = QueryValue(reg, "htmlfile\\shell\\open\\command")
> but the next lines ares problems (WindowsError [Errno 13] : Invalid data)
>    reg = OpenKey(HKEY_CLASSES_ROOT,"")
>    exefile = QueryValue(reg, "xmlfile\\shell\\Open\\command")
> The difference in registry is that the first key has a type of REG_SZ but
> the second key has a type of REG_EXPAND_SZ. I have tried to change
> QueryValue by QueryValueEx but the error is  [Errno 2] file not found.
> What is the solution ?.

QueryValue wants a simple value.  Also, it does appear QueryValue only 
handles REG_SZ, so QueryValueEx is needed.

Try this:

 >>> reg = OpenKey(HKEY_CLASSES_ROOT, "xmlfile\\shell\\Open\\command")
 >>> QueryValueEx(reg, None)
(u'"F:\\Program Files\\Internet Explorer\\iexplore.exe" -nohome', 2)


More information about the Python-list mailing list