[python-win32] Unreliable results with Winreg & WMI

Tim Roberts timr at probo.com
Wed Feb 25 19:19:31 CET 2009


Tim Roberts wrote:
> Ben wrote:
>   
>>> I have generally been getting better results using winreg than using WMI,
>>> but even Winreg (or config problems on our server) are causing me
>>> problems.  For example I'd use this code to find out if a certain
>>>
>>>     
>>>       
>> I'm beginning to think this is because of 32 vs 64 bit, because the server running the
>> script is 32-bit, and (I haven't checked all), but it seems that it works on 32 bit
>> servers but not 64-bit ones.  Is this possible, and if so, is there any way around the
>> problem? 
>>   
>>     
>
> Absolutely.  In one of the stupidest moves Microsoft has made in the
> last decade, they implemented an incredibly bizarre scheme called
> "registry redirection" and "file system redirection" which redirects
> registry and file system requests for a 32-bit process running on
> Win64.  For example, if a 32-bit process tries to open
> \Windows\System32\xxx.xxx, it will instead open
> \Windows\SysWow64\xxx.xxx.  The same thing happens to many keys within
> HKEY_LOCAL_MACHINE.  They apparently felt we were all too STUPID to
> correctly handle the 32-to-64 transition, even though we all managed to
> handle the exact same issues during the 16-to-32 transition 15 years ago.
>
> You can suppress this redirection by calling RegDisableReflectionKey for
> the key you want to talk to.  I do not know if this is exposed in _winreg.
>   

Whoops, I just noticed you're doing this on remote machines. 
RegDisableReflectionKey doesn't work for that.  Instead, when you call
OpenKey, you should be able to add KEY_WOW64_64KEY to your flags. 
That's 0x100.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list