获取Windows体系结构(32/64位版本)

发布于 2024-09-08 09:11:08 字数 1495 浏览 3 评论 0原文

我遇到了一个小问题:

我想获取操作系统的体系结构,问题是我的编程语言不支持此类功能。因此我需要从 Windows DLL(如 kernel32.dll)读取此信息
我确实尝试使用函数 GetNativeSystemInfo/GetVersionEx/GetSystemInfo 获取信息。
不幸的是我无法获得架构:/

是否有其他一些函数可以读取任何 Windows dll 中的架构?
(它不需要是 kernel32,它可以是任何 dll,但它必须存在于 win xp+ 中)

作为信息:我使用 Gupta (SQLWindows/Team devoloper)

Edit1:

typedef struct _SYSTEM_INFO {
  union {
    DWORD  dwOemId;
    struct {
      WORD wProcessorArchitecture;
      WORD wReserved;
    } ;
  } ;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
} SYSTEM_INFO;

这是来自 MSDN,我尝试使用 10 和 12 个参数调用此函数 (古普塔不支持结构)。
在 32 位上我得到:
替代文本 http://img714.imageshack.us/img714/1954/32bit.gif< /a>

在 64 位上我得到:
替代文本 http://img691.imageshack.us/img691/8978/64bit.gif< /a>

每次在 32 位上我都会得到 0 OemID 吗?或者更好的是在 64 位版本的 Windows 上填写 OemID everytiem?

谢谢帮助!!

问候
奥罗

i got a little problem:

im tring to get the architecture of the OS, the problem is my programming language doesnt support such functions. Therefore i need to read this information form an windows dll (like kernel32.dll)
i did try to get the infos with the functions GetNativeSystemInfo/GetVersionEx/GetSystemInfo.
Unfortunately i were not able to get the architecture :/

Are there some other Functions to read the architecture in any windows dll?
(it dosnt need to be kernel32 it can be any dll but it must exists in win xp+)

As info: im using Gupta (SQLWindows/Team devoloper)

Edit1:

typedef struct _SYSTEM_INFO {
  union {
    DWORD  dwOemId;
    struct {
      WORD wProcessorArchitecture;
      WORD wReserved;
    } ;
  } ;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
} SYSTEM_INFO;

thats the info from MSDN, i tried to call this Function with with 10 and 12 Parameters
(Gupta dosnt support structs).
On 32Bit i get:
alt text http://img714.imageshack.us/img714/1954/32bit.gif

on 64Bit i get:
alt text http://img691.imageshack.us/img691/8978/64bit.gif

do i get every time a 0 OemID on 32 bit? or better is the OemID everytiem filled on 64bit version of windows?

Thx for help!!

Greets
Auro

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅人 2024-09-15 09:11:08

GetNativeSystemInfo 是绝对是要使用的功能。如果您的应用是本机 64 位应用,则 GetNativeSystemInfoGetSystemInfo;否则,如果它在WOW64下运行,它将返回真实的系统属性,即使它是在模拟的32位环境中运行。

GetNativeSystemInfo 填充 SYSTEM_INFO 结构,其中的 wProcessorArchitecture 成员告诉您系统是 32 位(可能是 PROCESSOR_ARCHITECTURE_INTEL)还是 64 位(可能是 <代码>PROCESSOR_ARCHITECTURE_AMD64)。

如果您的语言没有此 Win API 函数的包装器,要使用它,您可以照常使用 LoadLibraryGetProcAddress,并且需要定义 当然是 SYSTEM_INFO 结构。

更新

定义

typedef struct _SYSTEM_INFO {
  WORD      wProcessorArchitecture;
  WORD      wReserved;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
} SYSTEM_INFO;

我会在(常见)32 位系统上 Then wProcessorArchitecture = 0 ,在(常见)64 位系统上定义 wProcessorArchitecture = 9 。这些分别是常量 PROCESSOR_ARCHITECTURE_INTELPROCESSOR_ARCHITECTURE_AMD64。这些是常见的 32 位和 64 位架构。 PROCESSOR_ARCHITECTURE_IA64 = 6 稍微不常见一些,PROCESSOR_ARCHITECTURE_UNKNOWN = 65535 也是如此。

更新

是的,我看到你的问题。在 C 语言中,union 表示您一次选择一个选项。也就是说,结构是

DWORD     dwOemId;
DWORD     dwPageSize;
LPVOID    lpMinimumApplicationAddress;
LPVOID    lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD     dwNumberOfProcessors;
DWORD     dwProcessorType;
DWORD     dwAllocationGranularity;
WORD      wProcessorLevel;
WORD      wProcessorRevision;

WORD      wProcessorArchitecture;
WORD      wReserved;
DWORD     dwPageSize;
LPVOID    lpMinimumApplicationAddress;
LPVOID    lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD     dwNumberOfProcessors;
DWORD     dwProcessorType;
DWORD     dwAllocationGranularity;
WORD      wProcessorLevel;
WORD      wProcessorRevision;

因为一个 DWORD 由与两个字 (2×2) 一样多的字节 (4) 组成,所以替代方案只是寻址(和命名)数据的两种方式整个结构。在我们的例子中,我们对 wProcessorArchitecture 一词更感兴趣,而不是 wProcessorArchitecture 的增强 dwOemId 和完全无趣的 wReserved代码>话。

GetNativeSystemInfo is definitely the function to use. If your app is a native 64-bit app, GetNativeSystemInfo is the same as GetSystemInfo; otherwise, if it runs under WOW64, it will return the true system properties, even if it is run in an emulated 32-bit environment.

GetNativeSystemInfo fills a SYSTEM_INFO structure, the wProcessorArchitecture member of which tells you whether the system is 32-bit (probably PROCESSOR_ARCHITECTURE_INTEL) or 64-bit (probably PROCESSOR_ARCHITECTURE_AMD64).

If your language does not have a wrapper for this Win API function, to use it, you can employ LoadLibrary and GetProcAddress as usual, and you need to define the SYSTEM_INFO structure, of course.

Update

I would define

typedef struct _SYSTEM_INFO {
  WORD      wProcessorArchitecture;
  WORD      wReserved;
  DWORD     dwPageSize;
  LPVOID    lpMinimumApplicationAddress;
  LPVOID    lpMaximumApplicationAddress;
  DWORD_PTR dwActiveProcessorMask;
  DWORD     dwNumberOfProcessors;
  DWORD     dwProcessorType;
  DWORD     dwAllocationGranularity;
  WORD      wProcessorLevel;
  WORD      wProcessorRevision;
} SYSTEM_INFO;

Then wProcessorArchitecture = 0 on a (common) 32-bit system, and wProcessorArchitecture = 9 on a (common) 64-bit system. These are just the constants PROCESSOR_ARCHITECTURE_INTEL and PROCESSOR_ARCHITECTURE_AMD64, respectively. These are the common 32-bit and 64-bit architectures. PROCESSOR_ARCHITECTURE_IA64 = 6 is slightly more uncommon, as is surely PROCESSOR_ARCHITECTURE_UNKNOWN = 65535.

Update

Yes, I see your problem. In C, union means that you choose one of the options at a time. That is, the structure is either

DWORD     dwOemId;
DWORD     dwPageSize;
LPVOID    lpMinimumApplicationAddress;
LPVOID    lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD     dwNumberOfProcessors;
DWORD     dwProcessorType;
DWORD     dwAllocationGranularity;
WORD      wProcessorLevel;
WORD      wProcessorRevision;

or

WORD      wProcessorArchitecture;
WORD      wReserved;
DWORD     dwPageSize;
LPVOID    lpMinimumApplicationAddress;
LPVOID    lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD     dwNumberOfProcessors;
DWORD     dwProcessorType;
DWORD     dwAllocationGranularity;
WORD      wProcessorLevel;
WORD      wProcessorRevision;

Because one DWORD consists of as many bytes (4) as two words (2×2), the alternatives are just two ways of adressing (and naming) the data of the entire structure. In our case, we are more interested in the wProcessorArchitecture word rather then the augment dwOemId of wProcessorArchitecture and the utterly uninteresting wReserved words.

彼岸花似海 2024-09-15 09:11:08

我想你确实喜欢这样

BOOL SafeGetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo)
{
    BOOL bRet = FALSE;

    do 
    {
        if (lpSystemInfo == NULL)
        {
            break;
        }

        typedef void(WINAPI *GetNativeSystemInfoProc) (LPSYSTEM_INFO lpSystemInfo);
        GetNativeSystemInfoProc pFun = (GetNativeSystemInfoProc)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo");
        if (NULL != pFun)
        {
            pFun(lpSystemInfo);
        }
        else
        {
            GetSystemInfo(lpSystemInfo);
        }

        bRet = TRUE;
    } while (FALSE);
    return bRet;
}


BOOL GetOSDisplayString( LPTSTR pszOS)
{
    GRS_USEPRINTF();

    OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
    SYSTEM_INFO si = {};
    BOOL bOsVersionInfoEx;
    DWORD dwType;

    if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
    {
        return FALSE;
    }

    //GetSystemInfo(&si);
    if (SafeGetNativeSystemInfo(&si) == FALSE)
    {
        return FALSE;
    }

    if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4 )
    {
        StringCchCopy(pszOS, BUFSIZE, _T("Microsoft "));

        if ( osvi.dwMajorVersion == 6 )
        {
            if( 0 == osvi.dwMinorVersion )
            {
                if( osvi.wProductType == VER_NT_WORKSTATION )
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows Vista "));
                }
                else
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2008 " ));
                }

            }
            else if( 1 == osvi.dwMinorVersion )
            {
                if( osvi.wProductType == VER_NT_WORKSTATION )
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows 7 "));
                }
                else
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows Unknown "));
                }
            }
            else
            {
                StringCchCat(pszOS, BUFSIZE, _T("Windows Unknown "));
            }

            GetProductInfo( 6, 0, 0, 0, &dwType);
            switch( dwType )
            {
            case PRODUCT_ULTIMATE:
                StringCchCat(pszOS, BUFSIZE, _T("Ultimate Edition" ));
                break;
            case PRODUCT_HOME_PREMIUM:
                StringCchCat(pszOS, BUFSIZE, _T("Home Premium Edition" ));
                break;
            case PRODUCT_HOME_BASIC:
                StringCchCat(pszOS, BUFSIZE, _T("Home Basic Edition" ));
                break;
            case PRODUCT_ENTERPRISE:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition" ));
                break;
            case PRODUCT_BUSINESS:
                StringCchCat(pszOS, BUFSIZE, _T("Business Edition" ));
                break;
            case PRODUCT_STARTER:
                StringCchCat(pszOS, BUFSIZE, _T("Starter Edition" ));
                break;
            case PRODUCT_CLUSTER_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Cluster Server Edition" ));
                break;
            case PRODUCT_DATACENTER_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition" ));
                break;
            case PRODUCT_DATACENTER_SERVER_CORE:
                StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition (core installation)" ));
                break;
            case PRODUCT_ENTERPRISE_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition" ));
                break;
            case PRODUCT_ENTERPRISE_SERVER_CORE:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition (core installation)" ));
                break;
            case PRODUCT_ENTERPRISE_SERVER_IA64:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition for Itanium-based Systems" ));
                break;
            case PRODUCT_SMALLBUSINESS_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Small Business Server" ));
                break;
            case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                StringCchCat(pszOS, BUFSIZE, _T("Small Business Server Premium Edition" ));
                break;
            case PRODUCT_STANDARD_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Standard Edition" ));
                break;
            case PRODUCT_STANDARD_SERVER_CORE:
                StringCchCat(pszOS, BUFSIZE, _T("Standard Edition (core installation)" ));
                break;
            case PRODUCT_WEB_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Web Server Edition" ));
                break;
            }

            if ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 )
            {
                StringCchCat(pszOS, BUFSIZE, _T( ", 64-bit" ));
            }
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
            {
                StringCchCat(pszOS, BUFSIZE, _T(", 64-bit"));
            }
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA64)
            {
                StringCchCat(pszOS, BUFSIZE, _T(", 64-bit"));
            }
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL )
            {
                StringCchCat(pszOS, BUFSIZE, _T(", 32-bit"));
            }
        }

        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
        {
            if( GetSystemMetrics(SM_SERVERR2) )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Windows Server 2003 R2, "));
            }
            else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Windows Storage Server 2003"));
            }
            else if( osvi.wProductType == VER_NT_WORKSTATION &&
                si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Windows XP Professional x64 Edition"));
            }
            else 
            {
                StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2003, "));
            }
            if ( osvi.wProductType != VER_NT_WORKSTATION )
            {
                if ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
                {
                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Datacenter Edition for Itanium-based Systems" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Enterprise Edition for Itanium-based Systems" ));
                    }
                }

                else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
                {
                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Datacenter x64 Edition" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    {                   
                        StringCchCat(pszOS, BUFSIZE, _T( "Enterprise x64 Edition" ));
                    }
                    else
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Standard x64 Edition" ));
                    }
                }

                else
                {
                    if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Compute Cluster Edition" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Datacenter Edition" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Enterprise Edition" ));
                    }
                    else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Web Edition" ));
                    }
                    else
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Standard Edition" ));
                    }
                }
            }
        }

        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
        {
            StringCchCat(pszOS, BUFSIZE, _T("Windows XP "));
            if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Home Edition" ));
            }
            else
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Professional" ));
            }
        }

        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
        {
            StringCchCat(pszOS, BUFSIZE, _T("Windows 2000 "));

            if ( osvi.wProductType == VER_NT_WORKSTATION )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Professional" ));
            }
            else 
            {
                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                {
                    StringCchCat(pszOS, BUFSIZE, _T( "Datacenter Server" ));
                }
                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                {
                    StringCchCat(pszOS, BUFSIZE, _T( "Advanced Server" ));
                }
                else
                {
                    StringCchCat(pszOS, BUFSIZE, _T( "Server" ));
                }
            }
        }

        // Include service pack (if any) and build number.

        if( _tcslen(osvi.szCSDVersion) > 0 )
        {
            StringCchCat(pszOS, BUFSIZE, _T(" ") );
            StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);
        }

        TCHAR buf[80];

        StringCchPrintf( buf, 80, _T(" (build %d)"), osvi.dwBuildNumber);
        StringCchCat(pszOS, BUFSIZE, buf);

        return TRUE; 
    }
    else
    {  
        GRS_PRINTF(_T( "This sample does not support this version of Windows.\n") );
        return FALSE;
    }
}

I think you do like this,

BOOL SafeGetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo)
{
    BOOL bRet = FALSE;

    do 
    {
        if (lpSystemInfo == NULL)
        {
            break;
        }

        typedef void(WINAPI *GetNativeSystemInfoProc) (LPSYSTEM_INFO lpSystemInfo);
        GetNativeSystemInfoProc pFun = (GetNativeSystemInfoProc)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetNativeSystemInfo");
        if (NULL != pFun)
        {
            pFun(lpSystemInfo);
        }
        else
        {
            GetSystemInfo(lpSystemInfo);
        }

        bRet = TRUE;
    } while (FALSE);
    return bRet;
}


BOOL GetOSDisplayString( LPTSTR pszOS)
{
    GRS_USEPRINTF();

    OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
    SYSTEM_INFO si = {};
    BOOL bOsVersionInfoEx;
    DWORD dwType;

    if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
    {
        return FALSE;
    }

    //GetSystemInfo(&si);
    if (SafeGetNativeSystemInfo(&si) == FALSE)
    {
        return FALSE;
    }

    if ( VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4 )
    {
        StringCchCopy(pszOS, BUFSIZE, _T("Microsoft "));

        if ( osvi.dwMajorVersion == 6 )
        {
            if( 0 == osvi.dwMinorVersion )
            {
                if( osvi.wProductType == VER_NT_WORKSTATION )
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows Vista "));
                }
                else
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2008 " ));
                }

            }
            else if( 1 == osvi.dwMinorVersion )
            {
                if( osvi.wProductType == VER_NT_WORKSTATION )
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows 7 "));
                }
                else
                {
                    StringCchCat(pszOS, BUFSIZE, _T("Windows Unknown "));
                }
            }
            else
            {
                StringCchCat(pszOS, BUFSIZE, _T("Windows Unknown "));
            }

            GetProductInfo( 6, 0, 0, 0, &dwType);
            switch( dwType )
            {
            case PRODUCT_ULTIMATE:
                StringCchCat(pszOS, BUFSIZE, _T("Ultimate Edition" ));
                break;
            case PRODUCT_HOME_PREMIUM:
                StringCchCat(pszOS, BUFSIZE, _T("Home Premium Edition" ));
                break;
            case PRODUCT_HOME_BASIC:
                StringCchCat(pszOS, BUFSIZE, _T("Home Basic Edition" ));
                break;
            case PRODUCT_ENTERPRISE:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition" ));
                break;
            case PRODUCT_BUSINESS:
                StringCchCat(pszOS, BUFSIZE, _T("Business Edition" ));
                break;
            case PRODUCT_STARTER:
                StringCchCat(pszOS, BUFSIZE, _T("Starter Edition" ));
                break;
            case PRODUCT_CLUSTER_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Cluster Server Edition" ));
                break;
            case PRODUCT_DATACENTER_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition" ));
                break;
            case PRODUCT_DATACENTER_SERVER_CORE:
                StringCchCat(pszOS, BUFSIZE, _T("Datacenter Edition (core installation)" ));
                break;
            case PRODUCT_ENTERPRISE_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition" ));
                break;
            case PRODUCT_ENTERPRISE_SERVER_CORE:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition (core installation)" ));
                break;
            case PRODUCT_ENTERPRISE_SERVER_IA64:
                StringCchCat(pszOS, BUFSIZE, _T("Enterprise Edition for Itanium-based Systems" ));
                break;
            case PRODUCT_SMALLBUSINESS_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Small Business Server" ));
                break;
            case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
                StringCchCat(pszOS, BUFSIZE, _T("Small Business Server Premium Edition" ));
                break;
            case PRODUCT_STANDARD_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Standard Edition" ));
                break;
            case PRODUCT_STANDARD_SERVER_CORE:
                StringCchCat(pszOS, BUFSIZE, _T("Standard Edition (core installation)" ));
                break;
            case PRODUCT_WEB_SERVER:
                StringCchCat(pszOS, BUFSIZE, _T("Web Server Edition" ));
                break;
            }

            if ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 )
            {
                StringCchCat(pszOS, BUFSIZE, _T( ", 64-bit" ));
            }
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
            {
                StringCchCat(pszOS, BUFSIZE, _T(", 64-bit"));
            }
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA64)
            {
                StringCchCat(pszOS, BUFSIZE, _T(", 64-bit"));
            }
            else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL )
            {
                StringCchCat(pszOS, BUFSIZE, _T(", 32-bit"));
            }
        }

        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
        {
            if( GetSystemMetrics(SM_SERVERR2) )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Windows Server 2003 R2, "));
            }
            else if ( osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Windows Storage Server 2003"));
            }
            else if( osvi.wProductType == VER_NT_WORKSTATION &&
                si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Windows XP Professional x64 Edition"));
            }
            else 
            {
                StringCchCat(pszOS, BUFSIZE, _T("Windows Server 2003, "));
            }
            if ( osvi.wProductType != VER_NT_WORKSTATION )
            {
                if ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
                {
                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Datacenter Edition for Itanium-based Systems" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Enterprise Edition for Itanium-based Systems" ));
                    }
                }

                else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 )
                {
                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Datacenter x64 Edition" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    {                   
                        StringCchCat(pszOS, BUFSIZE, _T( "Enterprise x64 Edition" ));
                    }
                    else
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Standard x64 Edition" ));
                    }
                }

                else
                {
                    if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Compute Cluster Edition" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Datacenter Edition" ));
                    }
                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Enterprise Edition" ));
                    }
                    else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Web Edition" ));
                    }
                    else
                    {
                        StringCchCat(pszOS, BUFSIZE, _T( "Standard Edition" ));
                    }
                }
            }
        }

        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
        {
            StringCchCat(pszOS, BUFSIZE, _T("Windows XP "));
            if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Home Edition" ));
            }
            else
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Professional" ));
            }
        }

        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
        {
            StringCchCat(pszOS, BUFSIZE, _T("Windows 2000 "));

            if ( osvi.wProductType == VER_NT_WORKSTATION )
            {
                StringCchCat(pszOS, BUFSIZE, _T( "Professional" ));
            }
            else 
            {
                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                {
                    StringCchCat(pszOS, BUFSIZE, _T( "Datacenter Server" ));
                }
                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
                {
                    StringCchCat(pszOS, BUFSIZE, _T( "Advanced Server" ));
                }
                else
                {
                    StringCchCat(pszOS, BUFSIZE, _T( "Server" ));
                }
            }
        }

        // Include service pack (if any) and build number.

        if( _tcslen(osvi.szCSDVersion) > 0 )
        {
            StringCchCat(pszOS, BUFSIZE, _T(" ") );
            StringCchCat(pszOS, BUFSIZE, osvi.szCSDVersion);
        }

        TCHAR buf[80];

        StringCchPrintf( buf, 80, _T(" (build %d)"), osvi.dwBuildNumber);
        StringCchCat(pszOS, BUFSIZE, buf);

        return TRUE; 
    }
    else
    {  
        GRS_PRINTF(_T( "This sample does not support this version of Windows.\n") );
        return FALSE;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文