Tim
Tim

Reputation: 2796

Accessing 64-bit registry from Haskell

I have a Windows program in Haskell (hence 32-bit). I want to access the 64-bit view of the registry. The Windows API says to use RegOpenKeyEx and to OR in KEY_WOW64_64KEY (0x200). (I am using the standard Haskell bindings to the Windows API that come with the Haskell Platform.)

In my program this ends up being:

  import qualified System.Win32.Registry as W32
  import qualified System.Win32.Types    as W32
  ...
      let kEY_WOW64_64KEY = 0x200 -- has no binding in the library currently
      let regSam = kEY_WOW64_64KEY .|. ... other flags
      bracket (W32.regOpenKeyEx rootCode kname regSam) W32.regCloseKey $ \k -> ...

However, I get the exception RegOpenKeyEx: invalid argument (The system cannot find the file specified.)

Inspecting the call in Process Monitor shows the following output: enter image description here

The API call somehow ended up dropping the flag and going into the Wow6432Node subtree. Also illustrated, despite the event alluding RegOpenKey I think it's really calling into RegOpenKeyEx as shown in the event's stack (and the binding's error message).

Any suggestions?

Thanks!

Upvotes: 4

Views: 354

Answers (1)

David Heffernan
David Heffernan

Reputation: 613282

The alternate registry view flags are:

KEY_WOW64_64KEY 0x0100  
KEY_WOW64_32KEY 0x0200  

But you wrote:

let kEY_WOW64_64KEY = 0x200

So you are actually asking for the 32 bit view. You need to write:

let kEY_WOW64_64KEY = 0x100

Upvotes: 5

Related Questions