AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Variables to differentiate between 32 and 64 bit?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Mgrep
Guest





PostPosted: Tue Dec 22, 2009 7:22 am    Post subject: Variables to differentiate between 32 and 64 bit? Reply with quote

When all Windows O/S's were 32 bit, having a single system variable such as "A_ProgramFiles" made sense.

However, now that we have O/S's that are 64 bits, with seperate directory branches for 32 and 64 bit apps/components, does AHK support variables that allow you to specify which one exactly you want? Or do you have to give an explicit path?
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Tue Dec 22, 2009 8:51 am    Post subject: Reply with quote

If you're specifically interested in getting the Program Files paths, it can be done with EnvGet.
Code:
EnvGet, ProgFiles32, ProgramFiles(x86)
if ProgFiles32 = ; Probably not on a 64-bit system.
    EnvGet, ProgFiles32, ProgramFiles
EnvGet, ProgFiles64, ProgramW6432
MsgBox % "32: " ProgFiles32 "`n64: " ProgFiles64
I am running Windows 7 64-bit. If I type "set program" into a 64-bit command prompt (Start, type "cmd.exe"), it lists these variables:
Code:
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
Typing the same into a 32-bit command prompt (Start, type "C:\Windows\SysWow64\cmd.exe"), lists this:
Code:
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files (x86)
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
The environment variable ProgramFiles appears to be consistent with AutoHotkey's A_ProgramFiles (A_ can be omitted), which actually uses the registry value ProgramFilesDir in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion. There are also other registry values containing the 32-bit and 64-bit paths, but I suppose the environment variables are easier to use.


If you want to detect whether the OS is 64-bit, you may use something like this:
Code:
if DllCall("IsWow64Process", "uint", DllCall("GetCurrentProcess"), "int*", isWow64process) && isWow64process
    MsgBox This OS is 64-bit.
However, this method will not work if AutoHotkey is ever ported to 64-bit. Wink The following should continue to work (and can be used to retrieve other system information):
Code:
VarSetCapacity(si,44)
DllCall("GetNativeSystemInfo", "uint", &si)
if ErrorLevel {
    MsgBox Windows XP or later required.
    ExitApp
}
arc := NumGet(si,0,"ushort")
MsgBox % arc=0 ? "x86" : arc=9 ? "x64" : arc=6 ? "IA64" : "UNKNOWN"
Back to top
View user's profile Send private message Visit poster's website
Mgrep
Guest





PostPosted: Tue Dec 22, 2009 5:32 pm    Post subject: Reply with quote

Well, it's not just that. I'm referring to working with the system variables in general.

For example, using your test of which Command Prompt is being run, if I set up a script to do this:

Code:

!F7::Run %A_WinDir%\system32\cmd.exe


...even though the Title Bar shows that what's loaded is the cmd.exe in system32, running "set program" shows it as the 32 bit version.
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Wed Dec 23, 2009 8:38 am    Post subject: Reply with quote

For that specific issue, refer to File System Redirector, How Run msconfig using AutoHotKey? or one of the other threads where it has been discussed.

I suppose there isn't much in general that is related to system variables in this context. Just note that 32-bit applications do not run directly on 64-bit Windows, but inside WOW64. They are essentially running in a 32-bit environment, so will not have direct access to the 64-bit environment variables. As for other system information, it's a matter of finding the appropriate Windows API.
Back to top
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 115

PostPosted: Mon Feb 15, 2010 8:42 pm    Post subject: Reply with quote

I think there needs to be variables to handle scripts so that they can run as expected whether on 32-bit Windows or 64-bit Windows. The workarounds are just too cumbersome and should just be integrated into AHK. There should perhaps be a flag like "#Redirect64 Off|On". Example:

Code:

#Redirect64 Off ; Bypasses File System & Registry Redirection for Scripts run on 64-bit Windows
RunWait, %comspec%, %A_ProgramFiles% ; Will run C:\Windows\Sysnative\cmd.exe (rather than C:\Windows\SysWOW64\cmd.exe) in the directory C:\Program Files (rather than C:\Program Files(x86) )
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, Software, Valuename, Value; is not redirected to HKEY_LOCAL_MACHINE\Software\Wow6432Node


Alternatively or in addition, there could be special variables and commands that default to the normal version if the script is run on 32-bit Windows:

ComspecW6432
A_ProgramFilesW6432
A_WindirW6432 (Would not redirect from System32 subdirectory)
RegReadW6432
RegWriteW6432
EnvGetW6432
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group