0

I am having difficulty do understand this. If I'm correct, A 32bit Python can't run a code and change registry values in 64bit. Do I get it right? Or is there a switch to turn on in which enables this functionality?

There is this: http://msdn.microsoft.com/en-us/library/aa384129%28v=VS.85%29.aspx

But how do I use it with the following code? http://www.blog.pythonlibrary.org/2010/03/20/pythons-_winreg-editing-the-windows-registry/

Thanks, Oz

oz123
  • 1,258
  • 5
  • 17
  • 34
  • You should just be able to replace KEY_ALL_ACCESS with (KEY_ALL_ACCESS KEY_WOW64_64KEY). If KEY_WOW64_64KEY isn't defined, use the explicit value 0x0100. – Harry Johnston Dec 15 '11 at 20:51
  • replace where? what is Flag in Windows terminology??? – oz123 Dec 16 '11 at 10:46
  • Where the existing code says KEY_ALL_ACCESS. A flag is a parameter, or a single bit in a parameter, which changes the behaviour of a function call. – Harry Johnston Jan 09 '12 at 22:27

1 Answers1

-1

edit: Sorry, I misunderstood the question. Do the flag thing. :p

If you are on a 64bit operating system, you will have a "folder" in the HKLM\Software and HKCU\Software keys named Wow6432Node. That is like a junction point that allows Windows to maintain backwards compatibility across architectures, and basically transparently redirects the 32bit program that is accessing the registry.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.85).aspx

So even if you are executing 32bit code, if you are on a 64bit version of Windows, modifying HKLM\Software\Mysoftware is the 64bit registry. If you needed to modify the 32bit registry, it would HKLM\Software\Wow6432Node\MySoftware.

Here I am about to set 32bit ODBC connections, even on a 64bit OS. It also works on a 32bit OS. No flag setting is required. This code works.

code

Ryan Ries
  • 55,481
  • 10
  • 142
  • 199
  • 2
    -1, this is wrong. 32-bit code accessing HKLM\Software\Mysoftware is NOT modifying the 64-bit registry, it is transparently redirected to HKLM\Software\Wow6432Node\MySoftware unless you explicitly specify KEY_WOW64_64KEY. – Harry Johnston Jan 09 '12 at 06:04
  • While I appreciate your candorous downvote, this 32bit code 100% works on both 32bit and 64bit versions of Windows. When on a 64bit OS you just have to be mindful of whether the key you want is actually down Wow6432Node or not. No flag-setting is required. I did not say that playing with the KEY_WOW64_64KEY flags will not work or is not an alternative, I'm just saying that you do not have to do it that way. If it was my wording that you disagreed with, then let the code speak for itself. – Ryan Ries Jan 09 '12 at 14:20
  • @RyanRies You should replace the screenshot of code with a code block containing the code. – jscott Jan 09 '12 at 14:23
  • You don't need to set a flag if you're wanting to write to the 32-bit view, from either 32-bit or 64-bit apps. But this question is about writing to the 64-bit view from a 32-bit app. So, depending on interpretation, your answer is either wrong or irrelevant to the question. – Harry Johnston Jan 09 '12 at 22:01
  • Regarding your code fragment: assuming this is meant to be 32-bit code as stated, you don't need to use Wow6432Node. The two paths are equivalent, so the if statement is redundant. – Harry Johnston Jan 09 '12 at 22:20
  • Also, looking for C:\Windows\SysWOW64 is not a reliable test, because C:\Windows might not be the Windows root directory. In 32-bit code, you should use IsWow64Process if you need to know whether the OS is 64-bit or not. (Determining whether the process is 32-bit or 64-bit, if this is necessary, is language-specific.) – Harry Johnston Jan 09 '12 at 22:23
  • You're right, Harry. I misunderstood the question. – Ryan Ries Jan 09 '12 at 23:53
  • You should be able to delete the answer yourself if that is what you want to do - isn't there a delete option right next to edit? – Harry Johnston Jan 10 '12 at 00:13
  • You are wrong in thinking that the two paths are equivalent. I can guarantee you that they are not. (On a 32bit system one of them does not exist and on a 64bit system you'd be modifying the 64bit view when you meant to edit the 32bit view.) I have nothing else to add to this question and will not be coming back to it, but I couldn't just let you say blatantly false things and not say anything. – Ryan Ries Jan 10 '12 at 14:21
  • @Ryan: sorry, but you're wrong about this. In a 32-bit process on a 64-bit system, SOFTWARE\xyzzy is automatically and silently redirected to SOFTWARE\Wow6432Node\xyzzy unless you explicitly specify the KEY_WOW64_64KEY. Try it! – Harry Johnston Jan 11 '12 at 01:03