如何得到操作系统确切的版本信息?

beizijing 2004-04-29 05:58:09
目前觉得有两种方法可行,可是都有相同地问题:
1.通过查注册表:在HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion键值下可以看到相关的信息。

问题:可是都是数字,我怎么可以确切地知道是那个版本,如可以判断是Windows 2000 Professional、Windows 2000 Server
、Windows 2000 Advanced Server或是Windows 2000 Datacenter Server?


2.通过windows函数GetVersionEx和OSVERSIONINFO结构可以得到,或是Environment可以得到版本地相关信息,可是也还是存在上述问题

以上两种方法,我只能知道是win2000,却不能知道是Professional、Server、Advanced Server还是Datacenter Server,

请问还有什办法可以知道详细地操作系统的版本的信息,请指教

...全文
143 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
shadowWind 2004-08-31
  • 打赏
  • 举报
回复
mark
jsrgmt 2004-04-30
  • 打赏
  • 举报
回复
to: mahatma_cn(鱼和胸罩不可兼得) ,我根据您的提示在微软网站下载了Core SDK来
更新,安装的时候说系统中已经有相关服务了!我想也应该是啊,因为我已经安装过
.net了,所以应该已经有更新的SDK了!这里有一个不明白的地方是:Platform SDK是
由操作系统的版本来决定的(如果没有更新过的话),还是由开发平台来决定的(如:
VC 6.0和VS.NET),如果是后者,我的系统中,不是有两个版本的SDK(VC6的和.NET的)?
请高手指点!
shootingstars 2004-04-30
  • 打赏
  • 举报
回复
呵呵,你既然安装了VC.net,为什么不直接用VC.net编译?

如果你实在不想使用vc.net,你需要在你的vc6的include目录路径中加入最新的psdk的include目录(应该使用vc.net的include目录也可以。),并且一定保证这个最新的目录在路径的第一个。
mahatma_cn 2004-04-30
  • 打赏
  • 举报
回复
因为你的vc6默认的include文件是那个vc6.0自带的,去查查看你的ide中头文件设置里是否有指向你安装的sdk头文件目录。如果没有,编译器就去找那个winbase.h。其实那个结构定义在sdk目录的winnt.h中。
如果你的sdk安装在vc之前,可能要选择整合环境设置。
beizijing 2004-04-29
  • 打赏
  • 举报
回复
我用是vc6.0,在它的msdn中定义的OSVERSIONINFOEX的结构为
typedef struct _OSVERSIONINFOEXA {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wReserved[2];
} OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;

可是在其它的文件中,如.net中的定义为:
typedef struct _OSVERSIONINFOEX {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[128];
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wSuiteMask;
BYTE wProductType;
BYTE wReserved;
} OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;

居然定义的结构不一样!我查了以前的一些帖子,也有人提出这样的问题,但没有解决,还希望各位指点
mahatma_cn 2004-04-29
  • 打赏
  • 举报
回复
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
beizijing 2004-04-29
  • 打赏
  • 举报
回复
更新vc中的sdk,还是我操作系统的sdk?
可不可以说的详细一些?麻烦了
mahatma_cn 2004-04-29
  • 打赏
  • 举报
回复
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Winnt.h; include Windows.h.
Unicode: Declared as Unicode and ANSI structures.
mahatma_cn 2004-04-29
  • 打赏
  • 举报
回复
更新你的sdk
beizijing 2004-04-29
  • 打赏
  • 举报
回复
楼上的,这个程序会出这个错误:error C2039: 'wProductType' : is not a member of '_OSVERSIONINFOEXA'
d:\microsoft visual studio\vc98\include\winbase.h(7998) : see declaration of '_OSVERSIONINFOEXA'
为什么?谢谢!
mahatma_cn 2004-04-29
  • 打赏
  • 举报
回复
#include <windows.h>
#include <stdio.h>

#define BUFSIZE 80

int main()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;

// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
// If that fails, try using the OSVERSIONINFO structure.

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

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

switch (osvi.dwPlatformId)
{
// Test for the Windows NT product family.
case VER_PLATFORM_WIN32_NT:

// Test for the specific product family.
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
printf ("Microsoft Windows Server 2003 family, ");

if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
printf ("Microsoft Windows XP ");

if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
printf ("Microsoft Windows 2000 ");

if ( osvi.dwMajorVersion <= 4 )
printf("Microsoft Windows NT ");

// Test for specific product on Windows NT 4.0 SP6 and later.
if( bOsVersionInfoEx )
{
// Test for the workstation type.
if ( osvi.wProductType == VER_NT_WORKSTATION )
{
if( osvi.dwMajorVersion == 4 )
printf ( "Workstation 4.0 " );
else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
printf ( "Home Edition " );
else
printf ( "Professional " );
}

// Test for the server type.
else if ( osvi.wProductType == VER_NT_SERVER )
{
if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
printf ( "Datacenter Edition " );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
printf ( "Enterprise Edition " );
else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
printf ( "Web Edition " );
else
printf ( "Standard Edition " );
}

else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
{
if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
printf ( "Datacenter Server " );
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
printf ( "Advanced Server " );
else
printf ( "Server " );
}

else // Windows NT 4.0
{
if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
printf ("Server 4.0, Enterprise Edition " );
else
printf ( "Server 4.0 " );
}
}
}
else // Test for specific product on Windows NT 4.0 SP5 and earlier
{
HKEY hKey;
char szProductType[BUFSIZE];
DWORD dwBufLen=BUFSIZE;
LONG lRet;

lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
0, KEY_QUERY_VALUE, &hKey );
if( lRet != ERROR_SUCCESS )
return FALSE;

lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
(LPBYTE) szProductType, &dwBufLen);
if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
return FALSE;

RegCloseKey( hKey );

if ( lstrcmpi( "WINNT", szProductType) == 0 )
printf( "Workstation " );
if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
printf( "Server " );
if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
printf( "Advanced Server " );

printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
}

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

if( osvi.dwMajorVersion == 4 &&
lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
{
HKEY hKey;
LONG lRet;

// Test for SP6 versus SP6a.
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
0, KEY_QUERY_VALUE, &hKey );
if( lRet == ERROR_SUCCESS )
printf( "Service Pack 6a (Build %d)\n", osvi.dwBuildNumber & 0xFFFF );
else // Windows NT 4.0 prior to SP6a
{
printf( "%s (Build %d)\n",
osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF);
}

RegCloseKey( hKey );
}
else // Windows NT 3.51 and earlier or Windows 2000 and later
{
printf( "%s (Build %d)\n",
osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF);
}


break;

// Test for the Windows 95 product family.
case VER_PLATFORM_WIN32_WINDOWS:

if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
{
printf ("Microsoft Windows 95 ");
if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
printf("OSR2 " );
}

if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
{
printf ("Microsoft Windows 98 ");
if ( osvi.szCSDVersion[1] == 'A' )
printf("SE " );
}

if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
{
printf ("Microsoft Windows Millennium Edition\n");
}
break;

case VER_PLATFORM_WIN32s:

printf ("Microsoft Win32s\n");
break;
}
return TRUE;
}

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧