Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- public class Is64BitDetection
- {
- public static bool Is64BitOperatingSystem()
- {
- if (IntPtr.Size == 8) // 64-bit programs run only on Win64
- {
- return true;
- }
- else // 32-bit programs run on both 32-bit and 64-bit Windows
- {
- // Detect whether the current process is a 32-bit process running on a 64-bit system.
- bool flag;
- return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") &&
- IsWow64Process(GetCurrentProcess(), out flag)) && flag);
- }
- }
- static bool DoesWin32MethodExist(string moduleName, string methodName)
- {
- IntPtr moduleHandle = GetModuleHandle(moduleName);
- if (moduleHandle == IntPtr.Zero)
- {
- return false;
- }
- return (GetProcAddress(moduleHandle, methodName) != IntPtr.Zero);
- }
- [DllImport("kernel32.dll")]
- static extern IntPtr GetCurrentProcess();
- [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
- static extern IntPtr GetModuleHandle(string moduleName);
- [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
- static extern IntPtr GetProcAddress(IntPtr hModule,
- [MarshalAs(UnmanagedType.LPStr)]string procName);
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);
- static bool is64BitOS = Is64BitOperatingSystem();
- // ===========================
- }
- */
- // ============ 64 bit detection ===========//
- /*
- static bool is64BitProcess = (IntPtr.Size == 8);
- static bool is64BitOS = is64BitProcess || IsWow64();
- [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
- [return: MarshalAs(UnmanagedType.Bool)]
- private static extern bool IsWow64Process( [In] IntPtr hProcess, [Out] out bool wow64Process );
- // lpSystemInfo);
- public static bool IsWow64()
- {
- //IntPtr.Size == 4 &&
- if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) ||
- Environment.OSVersion.Version.Major >= 6)
- {
- using (Process p = Process.GetCurrentProcess())
- {
- bool retVal;
- if (!IsWow64Process(p.Handle, out retVal))
- {
- return false;
- }
- return retVal;
- }
- }
- else
- {
- return false;
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement