AutoHotkey Community

It is currently May 27th, 2012, 12:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: July 27th, 2011, 5:29 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Hello, y'all! I have to provision over 100 computers, so I wrote an AutHotkey_L script to help me.

I need to use the same script on each computer, and some of them are 32bit Windows7 and some are 64bit Windows7, so I put both 32bit and 64bit AutoHotkey_L in my launching folder (I launch over a LAN network).

Now, I found this function in these forums to tell if I am using a 64bit computer or not. Problem is this:
32bit system + 32bit ahk = false
64bit system + 32bit ahk = true

64bit system + 64bit ahk = false !!!!

Any clues?


is64bit(){
ThisProcess := DllCall("GetCurrentProcess")
; If IsWow64Process() fails or can not be found, assume this process is not running under wow64.
; Otherwise, use the value returned in IsWow64Process.
if !DllCall("IsWow64Process", "uint", ThisProcess, "int*", IsWow64Process)
IsWow64Process := 1
;MsgBox % IsWow64Process ? "win64" : "win32"
return %IsWow64Process%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 7:00 pm 
Offline

Joined: February 6th, 2010, 5:17 pm
Posts: 57
This should give you either "32-bit" or "64-bit", depending on the version of Windows installed (but I can't test it on 64-bit):
Code:
for obj in ComObjGet("winmgmts:\\.\root\cimv2").ExecQuery("SELECT OSArchitecture FROM Win32_OperatingSystem")
  MsgBox, % obj.OSArchitecture


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 7:57 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Thank you. That, however, will work on the 64bit machine with autohotkey_L both 32 and 64 bit versions, but it won't work on my 32bit machine with 32bit ahk_L. I need this to work on both architectures with both versions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:24 pm 
Offline

Joined: June 28th, 2007, 1:08 am
Posts: 662
Take a look in this:
Code:
MsgBox, % "OS Type: " . A_OSType . "`nOS Version: " . A_OSVersion . "`nPointer Size: " . A_PtrSize
   . "`nAdmin: " . (If (A_IsAdmin == 1)?"Yes":"No") . "`n64 Bit OS: "
   . (If (InStr(A_ProgramFiles, "x86") > 0)?"Yes":"No") . "`nAHK Version: " . A_AhkVersion
   . "`nAHK Path: " . A_AhkPath
ExitApp


Pretty much, Im checking the A_ProgramFiles variable to see if it contains the x86 portion, which would indicate that it is on a 64 bit os. Not sure if that is going to work 100% of the time, but its worth a shot.

_________________
RECOMMENDED: AutoHotkey_L
Some of the code I write will not work without it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:29 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Hello! I actually thought of doing that, but rejected it for a more viable method. Maybe I'll just go back to that method. I haven't encountered a situation where someone would have a x86 Program Files in their 32 bit system yet! Thanks for the reminder, and the snippet.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:47 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
I tried out your snippet, however that only works if autohotkey is inside of a program files directory. With that all being said, I think this is better:


whatitis := is64bit()
MsgBox % whatitis ? "win64" : "win32" ;%

;See whether the computer is a 64bit operating system or not
;return 1 or 0
is64bit(){
ifexist, C:\Program Files (x86)
{
b = 1
}else{
b = 0
}
return b
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:50 pm 
Offline

Joined: December 19th, 2010, 5:32 am
Posts: 235
Shorter version:
Code:
MsgBox % 64Bit()

64Bit() {
    Return (FileExist("C:\Program Files (x86)")) ? 1 : 0
}


Last edited by zzzooo10 on July 27th, 2011, 9:51 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:51 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Funny thing, A_OSType always gives me WIN32_NT but I know for a fact it is 64bit Windows 7. a_ptrsize is even 8, while on my 32 bit system, I also get WIN32_NT with a pointer size of 4. Strange or I don't understand something!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:53 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Where do you get: OSArchitecture ? That gives me an error.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:54 pm 
Offline

Joined: December 19th, 2010, 5:32 am
Posts: 235
I changed it to return a Boolean value. Refresh page


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2011, 9:55 pm 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Sorry, I should've realized that. That is shorter (nicer!) Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2011, 1:27 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
The easest way I found is this:

Code:
Is64bit(){
    Return A_PtrSize = 8 ? 1 : 0
}


In 64 bit AHK L A_PtrSize is 8, in 32 bit AHK_L it is 4 and in AHK Basic it is blank.

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2011, 1:43 am 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Ha! That is even better! AND it is more viable! Great! Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2011, 3:52 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
A word of warning: A_PtrSize will tell you the "bitness" of the EXE which is running the script, not the "bitness" of the OS. If the EXE is 64-bit, so is the OS (at least, until a hypothetical >64-bit Windows OS comes out), but the reverse does not hold true.
BGM wrote:
Funny thing, A_OSType always gives me WIN32_NT
Win32 does not mean 32-bit Windows.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 28th, 2011, 3:59 am 
Offline

Joined: January 12th, 2011, 4:04 pm
Posts: 93
Location: Kansas City, USA
Yes, I just noticed that. a_ptrsize gave me the wrong value when I used in 32bit ahk.

Thanks for the tidbit about win32; I was suspecting that.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, jrav, MSN [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group