判断OS位数
#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <conio.h>
// 取得真实系统信息
VOID SafeGetNativeSystemInfo(__out LPSYSTEM_INFO lpSystemInfo)
{
if (NULL==lpSystemInfo) return;
typedef VOID (WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress( GetModuleHandle(_T("kernel32")), "GetNativeSystemInfo");;
if (NULL != fnGetNativeSystemInfo)
{
fnGetNativeSystemInfo(lpSystemInfo);
}
else
{
GetSystemInfo(lpSystemInfo);
}
}
// 获取操作系统位数
int GetSystemBits()
{
SYSTEM_INFO si;
SafeGetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return 64;
}
return 32;
}
int _tmain(int argc, _TCHAR* argv[])
{
const int nBitCode = GetProgramBits();
const int nBitSys = GetSystemBits();
_tprintf(_T("I am a %dbit Program, run on %dbit System."), nBitCode, nBitSys);
//
_getch();
return 0;
}
//-----------------------------------------------------
//判断OS位数
BOOL Is64BitOS()
{
typedef VOID (WINAPI *LPFN_GetNativeSystemInfo)( __out LPSYSTEM_INFO lpSystemInfo );
LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress( GetModuleHandleW(L"kernel32"),"GetNativeSystemInfo");
if(fnGetNativeSystemInfo)
{
SYSTEM_INFO stInfo = {0};
fnGetNativeSystemInfo( &stInfo);
if( stInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64
|| stInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
{
return TRUE;
}
}
return FALSE;
}
//判断windows进程位数
BOOL Is64BitPorcess(DWORD dwProcessID)
{
if (!Is64BitOS())
{
return FALSE;
}else
{
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwProcessID);
if(hProcess)
{
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( GetModuleHandleW(L"kernel32"),"IsWow64Process");
if (NULL != fnIsWow64Process)
{
BOOL bIsWow64 = FALSE;
fnIsWow64Process(hProcess,&bIsWow64);
CloseHandle(hProcess);
if (bIsWow64)
{
return FALSE;
}
else
{
return TRUE;
}
}
}
}
return FALSE;
}
//查看errorCode表示的具体Message
HKEY hKey = NULL;
LPCTSTR subKey = LPCTSTR("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\setup\\recoveryconsole");
long errorCode = 0;
errorCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, NULL, KEY_READ | KEY_WOW64_64KEY, &hKey);
TCHAR *buffer;
::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
errorCode,
0,
(LPTSTR)&buffer,
0,
NULL);
::MessageBox(NULL, buffer, NULL, 0);
LocalFree(buffer);
------山的那一边

浙公网安备 33010602011771号