Solution:
--------------------------------------------------------------------------------------------------------------------
1> For Linux
a) getconf WORD_BIT
b) file /sbin/init
c) uname -a
2> For HP-UX
#getconf HW_32_64_CAPABLE
#getconf HW_CPU_SUPP_BITS
#getconf KERNEL_BITS
3> For Solaris
isainfo -v
isainfo -kv
isainfo -b
4> For Windows
#include <windows.h>
#include <stdio.h>
BOOL IsWow64()
{
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"),"IsWow64Process");
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
return FALSE;
} else
return TRUE;
}
return bIsWow64;
}
int main()
{
BOOL f64;
f64 = IsWow64();
if (f64)
printf("64\n");
else
printf("32\n");
}
主要是利用了IsWow64Process,这是一个windows api,如果进程是运行在64位系统上的32位程序,则返回TRUE,我们用32位方式编译这个程序并运行,即可判断操作系统的位数。
补充Delphi版的,写出一个函数了,直接调用~
function RunningInWow64:boolean;
type
LPFN_ISWOW64PROCESS=function(Hand:Hwnd; Isit:Pboolean):boolean; stdcall;
var
pIsWow64Process:LPFN_ISWOW64PROCESS;
IsWow64:boolean;
begin
result:=false;
@pIsWow64Process:=GetProcAddress(GetModuleHandle('kernel32'),'IsWow64Process');
if @pIsWow64Process=nil then exit;
pIsWow64Process(GetCurrentProcess,@IsWow64);
result:=IsWow64;
end;
转自:http://hi.baidu.com/zhujian0805/blog/item/88c9af39dff7fefa3b87ce78.html/cmtid/061401ecf2b29ada2f2e2118
--------------------------------------------------------------------------------------------------------------------
1> For Linux
a) getconf WORD_BIT
b) file /sbin/init
c) uname -a
2> For HP-UX
#getconf HW_32_64_CAPABLE
#getconf HW_CPU_SUPP_BITS
#getconf KERNEL_BITS
3> For Solaris
isainfo -v
isainfo -kv
isainfo -b
4> For Windows
#include <windows.h>
#include <stdio.h>
BOOL IsWow64()
{
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL bIsWow64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"),"IsWow64Process");
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{
return FALSE;
} else
return TRUE;
}
return bIsWow64;
}
int main()
{
BOOL f64;
f64 = IsWow64();
if (f64)
printf("64\n");
else
printf("32\n");
}
主要是利用了IsWow64Process,这是一个windows api,如果进程是运行在64位系统上的32位程序,则返回TRUE,我们用32位方式编译这个程序并运行,即可判断操作系统的位数。
补充Delphi版的,写出一个函数了,直接调用~
function RunningInWow64:boolean;
type
LPFN_ISWOW64PROCESS=function(Hand:Hwnd; Isit:Pboolean):boolean; stdcall;
var
pIsWow64Process:LPFN_ISWOW64PROCESS;
IsWow64:boolean;
begin
result:=false;
@pIsWow64Process:=GetProcAddress(GetModuleHandle('kernel32'),'IsWow64Process');
if @pIsWow64Process=nil then exit;
pIsWow64Process(GetCurrentProcess,@IsWow64);
result:=IsWow64;
end;
转自:http://hi.baidu.com/zhujian0805/blog/item/88c9af39dff7fefa3b87ce78.html/cmtid/061401ecf2b29ada2f2e2118
ps:sizeof只能判断当前编译程序的位数,而非操作系统的位数。
方法1,msdn 有相应的例子,代码贴出来给你看看
MSDN有相应Example!
#include <windows.h>
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle( "kernel32 "), "IsWow64Process ");
BOOL IsWow64()
{
BOOL bIsWow64 = FALSE;
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
{// handle error
std::cout < < "Handle Error " < <std::endl;
}
}
return bIsWow64;
}
方法2:
GetSystemWow64Directory
判断这个文件夹是否存在

本文介绍了在不同操作系统(Linux, HP-UX, Solaris, Windows)中检测系统位数的方法,包括使用命令行工具和编程实现。通过getconf、uname、isainfo等命令,以及Windows API函数IsWow64Process,可以获取系统的位数信息。

959

被折叠的 条评论
为什么被折叠?



