Skip to content

Instantly share code, notes, and snippets.

@steinybot
Created March 28, 2019 05:19
Show Gist options
  • Save steinybot/95bc0a26a66e31c95b92b625c8f37493 to your computer and use it in GitHub Desktop.
Save steinybot/95bc0a26a66e31c95b92b625c8f37493 to your computer and use it in GitHub Desktop.
Check if the operating system is 64-bit
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