admin 管理员组

文章数量: 887021

获取版本代码

float getSysVersion(){

	float f_ret;

	typedef void(__stdcall*NTPROC)(DWORD*, DWORD*, DWORD*);
	DWORD dwMajor, dwMinor, dwBuildNumber;
	NTPROC proc = (NTPROC)GetProcAddress(
		LoadLibrary("ntdll.dll"),
		"RtlGetNtVersionNumbers"
	); proc(&dwMajor, &dwMinor, &dwBuildNumber); 

	// win 10
	if (dwMajor == 10 && dwMinor == 0){
		f_ret = dwMajor + dwMinor*0.1;
		return f_ret;
	}

	// win 8.1
	if (dwMajor == 6 && dwMinor == 3){
		f_ret = dwMajor + dwMinor*0.1;
		return f_ret;
	}

	// win 8.1 以下
	SYSTEM_INFO info;
	GetSystemInfo(&info);
	OSVERSIONINFOEX os;
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	#pragma warning(disable:4996)
	if(GetVersionEx((OSVERSIONINFO *)&os)){
		f_ret = os.dwMajorVersion + os.dwMinorVersion*0.1;
	}
	
	return f_ret;
}

效果图:

获取 ReleaseId

string get_systemReleaseId(){
	
	string releaseId = "";
	HKEY hKey_return = NULL;
	char keyValue[256];
    DWORD keySzType;
    DWORD keySize;

	if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\",0,KEY_READ,&hKey_return)){
		cout << "RegOpenKeyEx failed." << endl;
		goto end;
	}
	
	if(ERROR_SUCCESS != RegQueryValueEx(hKey_return,"ReleaseId",0,&keySzType,(LPBYTE)&keyValue,&keySize)){
		cout << "RegQueryValueEx failed." << endl;
		goto end;
	}
	
	releaseId = keyValue;
	
end:
	return releaseId;
}

本文标签: 版本 系统