首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

怎么判断操作系统是windows 7

2012-02-26 
如何判断操作系统是windows 7前几天你给的那个判断操作系统的代码很好!很详细!但就是无法判断windows 7,能

如何判断操作系统是windows 7
前几天你给的那个判断操作系统的代码很好!很详细!但就是无法判断windows 7,能否麻烦你修改一下,也适用于windows 7?非常感谢!

[解决办法]
一般都是用API GetVersionEx 
windows 7还没有正式版,还没稳定,有可能有变化,当前不需要过多考虑。

The GetVersionEx function obtains extended information about the version of the operating system that is currently running.

To obtain information for the operating system on a remote computer, use the NetWkstaGetInfo function, the Win32_OperatingSystem WMI class, or the OperatingSystem property of the IADsComputer interface.

To compare the current system version to a required version, use the VerifyVersionInfo function instead of using GetVersionEx to perform the comparison yourself.


BOOL GetVersionEx(
LPOSVERSIONINFO lpVersionInfo
);
Parameters
lpVersionInfo 
[in, out] Pointer to an OSVERSIONINFO data structure that the function fills with operating system version information. 
Before calling the GetVersionEx function, set the dwOSVersionInfoSize member of this structure to sizeof(OSVERSIONINFO).

Windows NT 4.0 SP6 and later: This member can be a pointer to an OSVERSIONINFOEX structure. Set the dwOSVersionInfoSize member to sizeof(OSVERSIONINFOEX) to identify the structure type.
Return Values
If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError. The function fails if you specify an invalid value for the dwOSVersionInfoSize member of the OSVERSIONINFO or OSVERSIONINFOEX structure.

Remarks
Identifying the current operating system is usually not the best way to determine whether a particular operating system feature is present. This is because the operating system may have had new features added in a redistributable DLL. Rather than using GetVersionEx to determine the operating system platform or version number, test for the presence of the feature itself. For more information, see Operating System Version.

To verify whether the current operating system is either Windows XP Media Center Edition or Tablet PC Edition, use the GetSystemMetrics function.

Example Code [C++]
When using the GetVersionEx function to determine whether your application is running on a particular version of the operating system, check for version numbers that are greater than or equal to the desired version numbers. This ensures that the test succeeds for later versions of the operating system. For example, if your application requires Windows XP, use the following test.

osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
bIsWindowsXPorLater = 
( (osvi.dwMajorVersion > 5) ||
( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) );

[解决办法]
那天回答完那个问题,我就改写好了,支持Windows 7(版本号为6.1)。呵呵。

C/C++ code
#include <shlwapi.h>#include <tchar.h>#include <stdio.h>#define BUFSIZE 256#define PRODUCT_ULTIMATE                            0x00000001#define PRODUCT_HOME_BASIC                          0x00000002#define PRODUCT_HOME_PREMIUM                        0x00000003#define PRODUCT_ENTERPRISE                          0x00000004#define PRODUCT_HOME_BASIC_N                        0x00000005#define PRODUCT_BUSINESS                            0x00000006#define PRODUCT_STANDARD_SERVER                     0x00000007#define PRODUCT_DATACENTER_SERVER                   0x00000008#define PRODUCT_SMALLBUSINESS_SERVER                0x00000009#define PRODUCT_ENTERPRISE_SERVER                   0x0000000A#define PRODUCT_STARTER                             0x0000000B#define PRODUCT_DATACENTER_SERVER_CORE              0x0000000C#define PRODUCT_STANDARD_SERVER_CORE                0x0000000D#define PRODUCT_ENTERPRISE_SERVER_CORE              0x0000000E#define PRODUCT_ENTERPRISE_SERVER_IA64              0x0000000F#define PRODUCT_BUSINESS_N                          0x00000010#define PRODUCT_WEB_SERVER                          0x00000011#define PRODUCT_CLUSTER_SERVER                      0x00000012#define PRODUCT_HOME_SERVER                         0x00000013#define PRODUCT_STORAGE_EXPRESS_SERVER              0x00000014#define PRODUCT_STORAGE_STANDARD_SERVER             0x00000015#define PRODUCT_STORAGE_WORKGROUP_SERVER            0x00000016#define PRODUCT_STORAGE_ENTERPRISE_SERVER           0x00000017#define PRODUCT_SERVER_FOR_SMALLBUSINESS            0x00000018#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM        0x00000019#define PRODUCT_HOME_PREMIUM_N                      0x0000001A#define PRODUCT_ENTERPRISE_N                        0x0000001B#define PRODUCT_ULTIMATE_N                          0x0000001C#define PRODUCT_WEB_SERVER_CORE                     0x0000001D#define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT    0x0000001E#define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY      0x0000001F#define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING     0x00000020#define PRODUCT_SMALLBUSINESS_SERVER_PRIME          0x00000021#define PRODUCT_HOME_PREMIUM_SERVER                 0x00000022#define PRODUCT_SERVER_FOR_SMALLBUSINESS_V          0x00000023#define PRODUCT_STANDARD_SERVER_V                   0x00000024#define PRODUCT_DATACENTER_SERVER_V                 0x00000025#define PRODUCT_ENTERPRISE_SERVER_V                 0x00000026#define PRODUCT_DATACENTER_SERVER_CORE_V            0x00000027#define PRODUCT_STANDARD_SERVER_CORE_V              0x00000028#define PRODUCT_ENTERPRISE_SERVER_CORE_V            0x00000029#define PRODUCT_HYPERV                              0x0000002A#define SM_TABLETPC             86#define SM_MEDIACENTER          87#define SM_STARTER              88#define SM_SERVERR2             89#define VER_SERVER_NT                       0x80000000#define VER_WORKSTATION_NT                  0x40000000#define VER_SUITE_SMALLBUSINESS             0x00000001#define VER_SUITE_ENTERPRISE                0x00000002#define VER_SUITE_BACKOFFICE                0x00000004#define VER_SUITE_COMMUNICATIONS            0x00000008#define VER_SUITE_TERMINAL                  0x00000010#define VER_SUITE_SMALLBUSINESS_RESTRICTED  0x00000020#define VER_SUITE_EMBEDDEDNT                0x00000040#define VER_SUITE_DATACENTER                0x00000080#define VER_SUITE_SINGLEUSERTS              0x00000100#define VER_SUITE_PERSONAL                  0x00000200#define VER_SUITE_BLADE                     0x00000400#define VER_SUITE_EMBEDDED_RESTRICTED       0x00000800#define VER_SUITE_SECURITY_APPLIANCE        0x00001000#define VER_SUITE_STORAGE_SERVER            0x00002000#define VER_SUITE_COMPUTE_SERVER            0x00004000#define VER_SUITE_WH_SERVER                 0x00008000typedef VOID (WINAPI *GETNATIVESYSTEMINFO)(LPSYSTEM_INFO);typedef BOOL (WINAPI *GETPRODUCTINFO)(DWORD , DWORD, DWORD, DWORD, PDWORD); 

热点排行