I have two .exe files, and I would like to create one program that will be able to run one of them based on the Windows bit size (ie, run program1.exe
if 64-bit and run program2.exe
if 32-bit). Does anyone know where I should start looking?
-
do you mean 32 or 64 bit?– KeltariApr 14, 2014 at 19:22
-
@Keltari yes. I've edited the question to make that more clear– yiweiApr 14, 2014 at 19:24
-
are these programs you wrote?– KeltariApr 14, 2014 at 19:28
-
no. they are installers, and i would just like to run them based on which version of windows is installed– yiweiApr 14, 2014 at 19:34
2 Answers
You could use a simple windows Powershell script as your launcher.
Here's how you can tell your architechure from PS: http://depsharee.blogspot.com/2011/06/how-do-detect-operating-system.html
The idea is to check how many bytes long the IntPtr structure is. 4=> 32b, 8 => 64b.
If you really want an exe, in DotNet, you could use this check to determine if its 64b:
BOOL Is64BitWindows() {
#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64
#elif defined(_WIN32)
// 32-bit programs run on both 32-bit and 64-bit Windows
// so must sniff
BOOL f64 = FALSE;
return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
return FALSE; // Win64 does not support Win16
#endif
}
more info here: http://blogs.msdn.com/b/oldnewthing/archive/2005/02/01/364563.aspx
-
-
1
-
-
@Ramhound, any of the scripts in the link to blogspot. they cover several methods, including WMI queries. I think the IntPtr is the most graceful though. Apr 14, 2014 at 21:33
You can always check the %programfiles(x86)%
environment variable. If it's a Windows 64-bit machine it will return the path to "Program Files (x86)", if it's not 64-bit it won't be defined and will just return "%programfiles(x86)%".
You can check this with a batch, PS, .Net, or whatever you'd like. :)