// : 定义控制台应用程序的入口点。
//
#include ""
#include <string>
#include <>
#include <>
#pragma comment(lib, "")
#define REG_K_OS_W L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
void GetSystemNameBy4X(const OSVERSIONINFOEX& os, std::string& strSystemName)
{
switch()
{
case 0:
if ( == VER_PLATFORM_WIN32_NT)
{
strSystemName = "Microsoft Windows NT 4.0";
// 1996.7发布
}
else if ( == VER_PLATFORM_WIN32_WINDOWS)
{
strSystemName = "Microsoft Windows 95";
}
break;
case 10:
strSystemName = "Microsoft Windows 98";
break;
case 90:
strSystemName = "Microsoft Windows Me";
break;
}// switch
}
void GetSystemNameBy5X(const OSVERSIONINFOEX& os, const SYSTEM_INFO& info, std::string& strSystemName)
{
switch()
{
case 0:
strSystemName = "Microsoft Windows 2000";
// 1999.12发布
break;
case 1:
strSystemName = "Microsoft Windows XP";
// 2001.8发布
break;
case 2:
if ( == VER_NT_WORKSTATION && == PROCESSOR_ARCHITECTURE_AMD64)
{
strSystemName = "Microsoft Windows XP Professional x64 Edition";
}
else if (GetSystemMetrics(SM_SERVERR2) == 0)
{
strSystemName = "Microsoft Windows Server 2003";
// 2003.3发布
}
else if (GetSystemMetrics(SM_SERVERR2) != 0)
{
strSystemName = "Microsoft Windows Server 2003 R2";
}
else
{
strSystemName = "Microsoft Windows Home Server";
}
break;
}
// switch
}
bool GetWin8dot1Name(std::string& strSystemName)
{
bool bRet = true;
do
{
HKEY hKey = NULL;
LONG lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
REG_K_OS_W,
0,
KEY_ALL_ACCESS,
&hKey);
if (ERROR_SUCCESS != lResult)
{
if (hKey)
{
lResult = RegCloseKey(hKey);
hKey = NULL;
}
bRet = false;
break;
}
DWORD dwType = 0;
char wszSystemName[MAX_PATH] = {0};
DWORD dwSize = sizeof(wszSystemName) / sizeof(wszSystemName[0]);
lResult = RegQueryValueExA(hKey,
"ProductName",
NULL,
&dwType,
(LPBYTE)wszSystemName,
(DWORD*)&dwSize);
if (ERROR_SUCCESS != lResult)
{
lResult = RegCloseKey(hKey);
hKey = NULL;
bRet = false;
break;
}
strSystemName = wszSystemName;
lResult = RegCloseKey(hKey);
} while (0);
return bRet;
}
void GetSystemNameBy6X(const OSVERSIONINFOEX& os, std::string& strSystemName)
{
switch()
{
case 0:
strSystemName = "Microsoft Windows Server 2008";
if ( == VER_NT_WORKSTATION)
{
strSystemName = "Microsoft Windows Vista";
}
break;
case 1:
strSystemName = "Microsoft Windows Server 2008 R2";
if ( == VER_NT_WORKSTATION)
{
strSystemName = "Microsoft Windows 7";
}
break;
case 2:
{
// 从注册列表中读取系统名
GetWin8dot1Name(strSystemName);
if (())
{
strSystemName = "Microsoft Windows Server 2012";
if (VER_NT_WORKSTATION == )
{
strSystemName = "Microsoft Windows 8";
}
}
}
break;
case 3:
strSystemName = "Microsoft Windows Server 2012 R2";
if (VER_NT_WORKSTATION == )
{
strSystemName = "Microsoft Windows 8.1";
}
break;
}// switch
};
void GetSystemNameBy10X(const OSVERSIONINFOEX& os, std::string& strSystemName)
{
switch()
{
case 0:
strSystemName = "Microsoft Windows Server 2016";
if (VER_NT_WORKSTATION == )
{
strSystemName = "Microsoft Windows 10";
}
break;
}
}
static bool GetSystemName(std::string& strSystemName)
{
bool bRet = true;
();
SYSTEM_INFO info;
ZeroMemory(&info, sizeof(SYSTEM_INFO));
GetSystemInfo(&info);
OSVERSIONINFOEX os;
= sizeof(OSVERSIONINFOEX);
bool bTrue = GetVersionEx((OSVERSIONINFO*)&os);
HINSTANCE hinst = LoadLibraryA("");
if (hinst)
{
typedef void (__stdcall *NTPROC)(DWORD*, DWORD*, DWORD*);
NTPROC
PRtlGetNtVersionNumbers = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
if (PRtlGetNtVersionNumbers)
{
PRtlGetNtVersionNumbers(&, &, &);
&= 0xFFFF;
}
::FreeLibrary(hinst);
hinst = NULL;
}
else
{
WKSTA_INFO_100* pInfo = NULL;
if (NERR_Success == NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pInfo))
{
= pInfo->wki100_ver_major;
= pInfo->wki100_ver_minor;
}
}
if (bTrue)
{
switch()
{
case 4:
GetSystemNameBy4X(os, strSystemName);
break;
// case 4
case 5:
GetSystemNameBy5X(os, info, strSystemName);
break;
// case 5
case 6:
GetSystemNameBy6X(os, strSystemName);
break;// case 6
case 10:
GetSystemNameBy10X(os, strSystemName);
break;
// case 10
default:
break;
}
}
return bRet;
}
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::string strName;
GetSystemName(strName);
std::cout << strName << std::endl;
return 0;
}
相关文章
- 获取windows操作系统名称和版本
- 获取操作系统名称和版本
- 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别
- Node.js windows版本 下载和安装(详细步骤)
- NDK版本、获取以及和ANDROID对应关系
- asp.net获取浏览器端操作系统名称
- 解决ubuntu(16.04版本)和windows电脑之间无法复制粘贴问题
- 在Windows平台使用源码编译和安装PyTorch3D指定版本
- windows和linux下获取当前程序路径以及cpu数
- docker 源码分析 四(基于1.8.2版本),Docker镜像的获取和存储