返回列表 发帖

[转帖]获取系统详细版本

  1. &#35;include <windows.h>
  2. &#35;include <stdio.h>
  3. &#35;define BUFSIZE 80
  4. int main()
  5. {
  6. OSVERSIONINFOEX osvi;
  7. BOOL bOsVersionInfoEx;
  8. // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
  9. // If that fails, try using the OSVERSIONINFO structure.
  10. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
  11. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  12. if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
  13. {
  14. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  15. if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
  16. {
  17. printf("can';t get os version !\n");
  18. return FALSE;
  19. }
  20. }
  21. switch (osvi.dwPlatformId)
  22. {
  23. // Test for the Windows NT product family.
  24. case VER_PLATFORM_WIN32_NT:
  25. // Test for the specific product family.
  26. if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
  27. printf ("Microsoft Windows Server 2003 family, ");
  28. if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
  29. printf ("Microsoft Windows XP ");
  30. if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
  31. printf ("Microsoft Windows 2000 ");
  32. if ( osvi.dwMajorVersion <= 4 )
  33. printf("Microsoft Windows NT ");
  34. // Test for specific product on Windows NT 4.0 SP6 and later.
  35. if( bOsVersionInfoEx )
  36. {
  37. // Test for the workstation type.
  38. if ( osvi.wProductType == VER_NT_WORKSTATION )
  39. {
  40. if( osvi.dwMajorVersion == 4 )
  41. printf ( "Workstation 4.0 " );
  42. else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
  43. printf ( "Home Edition " );
  44. else
  45. printf ( "Professional " );
  46. }
  47. // Test for the server type.
  48. else if ( osvi.wProductType == VER_NT_SERVER )
  49. {
  50. if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
  51. {
  52. if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  53. printf ( "Datacenter Edition " );
  54. else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  55. printf ( "Enterprise Edition " );
  56. else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
  57. printf ( "Web Edition " );
  58. else
  59. printf ( "Standard Edition " );
  60. }
  61. else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
  62. {
  63. if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
  64. printf ( "Datacenter Server " );
  65. else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  66. printf ( "Advanced Server " );
  67. else
  68. printf ( "Server " );
  69. }
  70. else // Windows NT 4.0
  71. {
  72. if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
  73. printf ("Server 4.0, Enterprise Edition " );
  74. else
  75. printf ( "Server 4.0 " );
  76. }
  77. }
  78. }
  79. else // Test for specific product on Windows NT 4.0 SP5 and earlier
  80. {
  81. HKEY hKey;
  82. char szProductType[BUFSIZE];
  83. DWORD dwBufLen=BUFSIZE;
  84. LONG lRet;
  85. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  86. "SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
  87. 0, KEY_QUERY_VALUE, &hKey );
  88. if( lRet != ERROR_SUCCESS )
  89. {
  90. printf("open regedit false! please try it again!\n");
  91. return FALSE;
  92. }
  93. lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL,
  94. (LPBYTE) szProductType, &dwBufLen);
  95. if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
  96. {
  97. printf("read regedit false! please try it again!\n");
  98. return FALSE;
  99. }
  100. RegCloseKey( hKey );
  101. if ( lstrcmpi( "WINNT", szProductType) == 0 )
  102. printf( "Workstation " );
  103. if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
  104. printf( "Server " );
  105. if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
  106. printf( "Advanced Server " );
  107. printf( "%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion );
  108. }
  109. // Display service pack (if any) and build number.
  110. if( osvi.dwMajorVersion == 4 &&
  111. lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
  112. {
  113. HKEY hKey;
  114. LONG lRet;
  115. // Test for SP6 versus SP6a.
  116. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  117. "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009",
  118. 0, KEY_QUERY_VALUE, &hKey );
  119. if( lRet == ERROR_SUCCESS )
  120. printf( "Service Pack 6a (Build %d)\n", osvi.dwBuildNumber & 0xFFFF );
  121. else // Windows NT 4.0 prior to SP6a
  122. {
  123. printf( "%s (Build %d)\n",
  124. osvi.szCSDVersion,
  125. osvi.dwBuildNumber & 0xFFFF);
  126. }
  127. RegCloseKey( hKey );
  128. }
  129. else // Windows NT 3.51 and earlier or Windows 2000 and later
  130. {
  131. printf( "%s (Build %d)\n",
  132. osvi.szCSDVersion,
  133. osvi.dwBuildNumber & 0xFFFF);
  134. }
  135. break;
  136. // Test for the Windows 95 product family.
  137. case VER_PLATFORM_WIN32_WINDOWS:
  138. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
  139. {
  140. printf ("Microsoft Windows 95 ");
  141. if ( osvi.szCSDVersion[1] == ';C'; || osvi.szCSDVersion[1] == ';B'; )
  142. printf("OSR2 " );
  143. }
  144. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
  145. {
  146. printf ("Microsoft Windows 98 ");
  147. if ( osvi.szCSDVersion[1] == ';A'; )
  148. printf("SE " );
  149. }
  150. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
  151. {
  152. printf ("Microsoft Windows Millennium Edition\n");
  153. }
  154. break;
  155. case VER_PLATFORM_WIN32s:
  156. printf ("Microsoft Win32s\n");
  157. break;
  158. }
  159. getchar();
  160. return TRUE;
  161. }
复制代码

[转帖]获取系统详细版本

不过需要个比较新的SDK升级包支持

TOP

[转帖]获取系统详细版本

能不能简单注释一下?

TOP

[转帖]获取系统详细版本

注释在代码里面有
不过是英文的。

TOP

返回列表 回复 发帖