Jump to content
Sign in to follow this  
GEOSoft

64 bit registry question

Recommended Posts

GEOSoft

I'm witing a short registry script that must run on all architectures. I don't have a 64 bit box to test this on but I need to verify that this code is correct.

If @ProcessorArch = "X86" Then
   $rHive = "HKLM"
Else
   $rHive = "HKLM64"
EndIf

Thanks

Edit: If you test this, please let me know which architecture you tested it on ( ClipPut(@ProcessorArch) ).

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
martin

I'm witing a short registry script that must run on all architectures. I don't have a 64 bit box to test this on but I need to verify that this code is correct.

If @ProcessorArch = "X86" Then
   $rHive = "HKLM"
Else
   $rHive = "HKLM64"
EndIf

Thanks

Just for my education, does a 64 bit processor necessarily have a 64 bit operating system?

(I could check your code on my son's computer when he releases his girlfriend from his bedroom, but someone else will probably answer before that.)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
GEOSoft

Just for my education, does a 64 bit processor necessarily have a 64 bit operating system?

(I could check your code on my son's computer when he releases his girlfriend from his bedroom, but someone else will probably answer before that.)

Not necessarily. You can still run a 32 bit OS or application on a 64 bit machine. You just don't get the advantages of running 64 bit. As for your sons current status "No comment." :D

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
martin

Not necessarily. You can still run a 32 bit OS or application on a 64 bit machine. You just don't get the advantages of running 64 bit.

So in that case detecting X64 or IA64 doesn't mean that HKLM64 will exist, so maybe you should be detecting something else which tells you that a 64-bit OS is installed. Like If FileExist('@SystemDir\ndfetw.dll') which is only found on 64 bit versions of windows. (Only found on Vista, I'm getting confused.)

EDIT: Strike out rubbish.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

I use something like this

$HKCU = "HKEY_CURRENT_USER"
$HKLM = "HKEY_LOCAL_MACHINE"
$HKU = "HKEY_USERS"
$HKCU = "HKEY_CURRENT_USER"
$HKCR = "HKEY_CLASSES_ROOT"
$HKCC = "HKEY_CURRENT_CONFIG"

If @ProcessorArch = "X64" Then
    $HKCU = "HKEY_CURRENT_USER64"
    $HKLM = "HKEY_LOCAL_MACHINE64"
    $HKU = "HKEY_USERS64"
    $HKCU = "HKEY_CURRENT_USER64"
    $HKCR = "HKEY_CLASSES_ROOT64"
    $HKCC = "HKEY_CURRENT_CONFIG64"
EndIf

maybe adding something like @OSType

will cover everything

Emiel


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
GEOSoft

So in that case detecting X64 or IA64 doesn't mean that HKLM64 will exist, so maybe you should be detecting something else which tells you that a 64-bit OS is installed. Like If FileExist('@SystemDir\ndfetw.dll') which is only found on 64 bit versions of windows. (Only found on Vista, I'm getting confused.)

EDIT: Strike out rubbish.

I think you are correct. @ProcessorArch won't do it. On the other hand I don't think @OSVersion will either.

I may have to do a RegRead() on a known 32 bit key and If @Error = 2 Then it's 64 bit.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

I use something like this

$HKCU = "HKEY_CURRENT_USER"
$HKLM = "HKEY_LOCAL_MACHINE"
$HKU = "HKEY_USERS"
$HKCU = "HKEY_CURRENT_USER"
$HKCR = "HKEY_CLASSES_ROOT"
$HKCC = "HKEY_CURRENT_CONFIG"

If @ProcessorArch = "X64" Then
    $HKCU = "HKEY_CURRENT_USER64"
    $HKLM = "HKEY_LOCAL_MACHINE64"
    $HKU = "HKEY_USERS64"
    $HKCU = "HKEY_CURRENT_USER64"
    $HKCR = "HKEY_CLASSES_ROOT64"
    $HKCC = "HKEY_CURRENT_CONFIG64"
EndIf

maybe adding something like @OSType

will cover everything

Emiel

That's pretty much what I was doing but I only used the one key as an example. However as martin just pointed out the keys are based on the Windows version and @OSVersion will bot return anything special for 64 bit that I know of.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
martin

That's pretty much what I was doing but I only used the one key as an example. However as martin just pointed out the keys are based on the Windows version and @OSVersion will bot return anything special for 64 bit that I know of.

I think you need something like this

;IsOS64 returns true if OS is 64 bit
;IsWOW64Process function only exists on 64 bit windows
Func IsOS64()
    Local $hUser32 = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "user32.dll")
    Local $OS64 = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hUser32[0], "str", "IsWow64Process")
    return $OS64[0] <> 0
endfunc
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
GEOSoft

I think you need something like this

;IsOS64 returns true if OS is 64 bit
;IsWOW64Process function only exists on 64 bit windows
Func IsOS64()
    Local $hUser32 = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "user32.dll")
    Local $OS64 = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hUser32[0], "str", "IsWow64Process")
    return $OS64[0] <> 0
endfunc
That's exactly what it needs martin. Thanks a lot. As a matter of fact I would suggest that this be posted on the Wiki and perhaps also included somewhere in the help file.

Here is what I finally came up with

Declare this with the other Global variables in your script

Global $kCR, $kCU, $kLM, $kU, $kCC
_Get_RegKeys()

Add these functions in your script.

Func _Get_RegKeys()
   If _64BitOS() Then
      $kCR = "HKCR64"
      $kCU = "HKCU64"
      $kLM = "HKLM64"
      $kU = "HKU64"
      $kCC = "HKCC64"
   Else
      $kCR = "HKCR"
      $kCU = "HKCU"
      $kLM = "HKLM"
      $kU = "HKU"
      $kCC = "HKCC"
   EndIf
EndFunc

Func _64BitOS();; Returns true if OS is 64 bit (credits go to martin)
   Local $hUser32 = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "user32.dll")
   Local $OS64 = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hUser32[0], "str", "IsWow64Process")
   Return $OS64[0] <> 0
Endfunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
james3mg

My computer is dual-64-bit processors, but I'm running Vista 32-bit (don't ask...I need access to old drivers). If I run

MsgBox(0,"hi",@ProcessorArch)
the message box displays X86. And yes, I'm quite sure my processors are 64-bit: I've installed many flavors of 64-bit OSes on it before. I think that @ProcessorArch actually checks the OS arch, not what the processor's capable of. So...problem solved, no?


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites
GEOSoft

My computer is dual-64-bit processors, but I'm running Vista 32-bit (don't ask...I need access to old drivers). If I run

MsgBox(0,"hi",@ProcessorArch)
the message box displays X86. And yes, I'm quite sure my processors are 64-bit: I've installed many flavors of 64-bit OSes on it before. I think that @ProcessorArch actually checks the OS arch, not what the processor's capable of. So...problem solved, no?
That could be, but I'm not sure that I would trust it as much as martins solution. I was using @ProcessorArch (see first post) but if that macro is doing what it is described as doing then it should be reporting 64 bit in your case. Your results would indicate to me that either the description for the macro is wrong or there is a bug in that code. Or there is the posibility that the macro is just named incorrectly and my original code is correct. I'll stay with martins solution until a dev can confirm what's happening here.

Thanks for the insight james.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
martin

That's exactly what it needs martin. Thanks a lot. As a matter of fact I would suggest that this be posted on the Wiki and perhaps also included somewhere in the help file.

Here is what I finally came up with

Declare this with the other Global variables in your script

Global $kCR, $kCU, $kLM, $kU, $kCC
_Get_RegKeys()

Add these functions in your script.

Func _Get_RegKeys()
   If _64BitOS() Then
      $kCR = "HKCR64"
      $kCU = "HKCU64"
      $kLM = "HKLM64"
      $kU = "HKU64"
      $kCC = "HKCC64"
   Else
      $kCR = "HKCR"
      $kCU = "HKCU"
      $kLM = "HKLM"
      $kU = "HKU"
      $kCC = "HKCC"
   EndIf
EndFunc

Func _64BitOS();; Returns true if OS is 64 bit (credits go to martin)
   Local $hUser32 = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "user32.dll")
   Local $OS64 = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hUser32[0], "str", "IsWow64Process")
   Return $OS64[0] <> 0
Endfunc

I''m glad you like that function GEOSoft, but when I said "something like this" that was my way of saying I haven't tried it. Do you know if it returns true on a 64 bit OS?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
GEOSoft

I''m glad you like that function GEOSoft, but when I said "something like this" that was my way of saying I haven't tried it. Do you know if it returns true on a 64 bit OS?

We need someone to try that but it looks to me like it should. I'll leave it as is until we find someone running a 64 bit OS that can state categorically that it doesn't.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Jon

ProcessorArch returns X64 on my system (Vista 64bit). We were actually having a dev conversation about the bad naming of these macros.

Edit: that is, ProcessorArch returns the OS type of 32/64bit nothing to do with the actual processor!

Share this post


Link to post
Share on other sites
GEOSoft

ProcessorArch returns X64 on my system (Vista 64bit). We were actually having a dev conversation about the bad naming of these macros.

That would seem correct Jon. The issue seems to be more of what should it return when running a 32 bit OS on a machine with a 64 bit processor. That's not your average setup I grant you, but the return could be critical as in the case james3mp has pointed out. BTW could you please (since you have 64 bit) check the code posted by martin and see if it returns True for your system? Thanks

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Jon

That would seem correct Jon. The issue seems to be more of what should it return when running a 32 bit OS on a machine with a 64 bit processor. That's not your average setup I grant you, but the return could be critical as in the case james3mp has pointed out. BTW could you please (since you have 64 bit) check the code posted by martin and see if it returns True for your system? Thanks

x64 processor running x86 OS = x86. It should be called OSArch

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

maybe a small documentation update

which explains @ProcessorArch displays OS Architecture and not the true ProcessorArchitecture


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites
Jon

maybe a small documentation update

which explains @ProcessorArch displays OS Architecture and not the true ProcessorArchitecture

I think we need a true processorarch as well. Which tells if the chip is x64 or not regardless of OS type.

Share this post


Link to post
Share on other sites
GEOSoft

I think we need a true processorarch as well. Which tells if the chip is x64 or not regardless of OS type.

I agree with this 100% but I can just hear the mumbles from Valik now. :D In the meantime I can switch the code back to @ProcessorArch but before I do that, did you test martins code with 64bit processor and 64 bit OS? it should return True. If it does then I'll leave my code as is so it doesn't get broken if you do change the macros. Assumably the existing @ProcessorArch would become @OSArch and a new @ProcessorArch developed.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.