Microsoft Windows 2000 (Windows NT 5.0) (1999) (2000-2010) 10年
Microsoft Windows XP (Windows NT 5.1) (2001-2014.4.8) 13年
Microsoft Windows Server 2003 (Windows NT 5.2) (2003-2015) 12年
Microsoft Windows Server 2003 R2 (Windows NT 5.2) (2006-2015) 9年
Microsoft Windows Vista (Windows NT 6.0) (2006-2017) 11年
Microsoft Windows Server 2008 (Windows NT 6.0) (2008-2018) 10年
Microsoft Windows 7 (Windows NT 6.1) (2009-2020) 11年
Microsoft Windows Server 2008 R2 (Windows NT 6.1) (2009-2018) 9年
Microsoft Windows 8.0 (Windows NT 6.2) (2012-2016) 4年
Microsoft Windows Server 2012(Windows NT 6.2) (2012-2023) 11年
Microsoft Windows Phone 8 (Windows NT 6.2) (2012-2014) 2年 [2]
Microsoft Windows 8.1 (未安装更新的)(Windows NT 6.3) (2013-2014) 1年
Microsoft Windows 8.1 (已安装更新的)(Windows NT 6.3) (2013-2023)10年
Microsoft Windows Server 2012 R2 (Windows NT 6.3) (2013-2023) 11年
Microsort Windows 10【Windows NT 10.0
// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//#pragma once
//#define _AFXDLL
#include "targetver.h"#include
#include // TODO: 在此处引用程序需要的其他头文件#include // MFC core and standard components
#include
#pragma comment(lib, "Setupapi.lib")
(2).targetver.h保持不变
(3).新建AutorunDlg.h
#pragma once
#include "afxwin.h"
class CAutorunDlg : public CDialog
{
public:LPTSTR GetOperatorSystemVer(void);BOOL GetOsVersion(RTL_OSVERSIONINFOEXW* pk_OsVer);
};
4.主程序ConsoleApplication1.cpp
#include "StdAfx.h"
//#include "GetLanaguagAndOsver.h"
#pragma comment(lib,"Kernel32.lib")
#include
#pragma comment(lib,"winmm.lib")
#include "AutorunDlg.h"
#include
//#pragma warning(disable:4996)
LPTSTR CAutorunDlg::GetOperatorSystemVer(void)
{//LPTSTR os;LPTSTR os = (LPTSTR)new char[20];ZeroMemory(os,40);RTL_OSVERSIONINFOEXW os_ver;GetOsVersion(&os_ver);if ((os_ver.dwMajorVersion == 5) && (os_ver.dwMinorVersion == 0)){os = _T("2000");}else if ((os_ver.dwMajorVersion == 5) && (os_ver.dwMinorVersion == 1)){ os = _T("xp");}else if ((os_ver.dwMajorVersion == 5) && (os_ver.dwMinorVersion == 2)){os = _T("2003 or xp64");//2003 // xp64 , }else if ((os_ver.dwMajorVersion == 6) && (os_ver.dwMinorVersion == 0)){os = _T("VISTA");;//AfxMessageBox(_T("VISTA"));}else if ((os_ver.dwMajorVersion == 6) && (os_ver.dwMinorVersion == 1)){//AfxMessageBox(_T("WIN7"));os = _T("win7");}else if ((os_ver.dwMajorVersion == 6) && (os_ver.dwMinorVersion == 2)){os = _T("WIN8"); //AfxMessageBox(_T("WIN8"));}else if ((os_ver.dwMajorVersion == 6) && (os_ver.dwMinorVersion == 3)){os = _T("WIN81"); //AfxMessageBox(_T("WIN81"));}else if ((os_ver.dwMajorVersion == 10) && (os_ver.dwMinorVersion == 0)){os = _T("WIN10");//AfxMessageBox(_T("WIN10"));//printf("%d", iVer);}return os;
}BOOL CAutorunDlg::GetOsVersion(RTL_OSVERSIONINFOEXW* pk_OsVer)
{typedef LONG(WINAPI* tRtlGetVersion)(RTL_OSVERSIONINFOEXW*);memset(pk_OsVer, 0, sizeof(RTL_OSVERSIONINFOEXW));pk_OsVer->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);HMODULE h_NtDll = GetModuleHandleW(L"ntdll.dll");tRtlGetVersion f_RtlGetVersion = (tRtlGetVersion)GetProcAddress(h_NtDll, "RtlGetVersion");if (!f_RtlGetVersion)return FALSE; // This will never happen (all processes load ntdll.dll)LONG Status = f_RtlGetVersion(pk_OsVer);return Status == 0; // STATUS_SUCCESS;
}int main(){CAutorunDlg OSver;LPTSTR system;system = OSver.GetOperatorSystemVer();printf("the system is %S\n", system);//getchar(); return 0;
}