Created
March 28, 2019 05:19
-
-
Save steinybot/95bc0a26a66e31c95b92b625c8f37493 to your computer and use it in GitHub Desktop.
Check if the operating system is 64-bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sun.jna.Platform; | |
import com.sun.jna.platform.win32.Kernel32; | |
import com.sun.jna.platform.win32.Kernel32Util; | |
import com.sun.jna.platform.win32.WinNT; | |
import com.sun.jna.ptr.IntByReference; | |
class Scratch { | |
public static void main(final String[] args) { | |
System.out.println("Is 64-bit OS? " + is64BitOS()); | |
} | |
public static boolean is64BitOS() { | |
return Platform.is64Bit() || (Platform.isWindows() && isRunningUnderWow64()); | |
} | |
private static boolean isRunningUnderWow64() throws UnsatisfiedLinkError, RuntimeException { | |
final IntByReference res = new IntByReference(); | |
final WinNT.HANDLE currentProcess = Kernel32.INSTANCE.GetCurrentProcess(); | |
if (!Kernel32.INSTANCE.IsWow64Process(currentProcess, res)) { | |
// TODO: Do something more sensible. | |
throw new RuntimeException("Failed to check if the current process is running under WOW64. " + Kernel32Util.getLastErrorMessage()); | |
} | |
return res.getValue() != 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment