1

我想知道Win Api来检测Windows操作系统是服务器(2003/2008)还是工作站(XP/Vista/Win7)?

4

2 回答 2

2

致电GetVersionEx获取OSVERSIONINFOEX信息并进行测试wProductType

于 2012-07-20T06:55:24.740 回答
1

它是这样的:

OSVERSIONINFOEX osvi;
BOOL bIsWindowsXPorLater;

ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

GetVersionEx((LPOSVERSIONINFO )&osvi);

if(osvi.wProductType == VER_NT_WORKSTATION)
{
    // Workstation
    printf("VER_NT_WORKSTATION.\n");

}
else
{
    // Server
    if(osvi.wProductType == VER_NT_DOMAIN_CONTROLLER)
    {
        printf("DOMAIN_CONTROLLER.\n");
    }

    if(osvi.wProductType == VER_NT_SERVER)
    {
        printf("SERVER.\n");      
    }
}

你还需要 kernel.lib

于 2012-07-20T08:25:57.433 回答