Last active
December 21, 2015 00:19
-
-
Save kyle-go/6219068 to your computer and use it in GitHub Desktop.
MS problem...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| #include <windows.h> | |
| #pragma comment(lib, "Advapi32.lib") | |
| std::string getOSInfo() | |
| { | |
| std::string value; | |
| HKEY result; | |
| BYTE data[MAX_PATH] = {0}; | |
| DWORD length = MAX_PATH; | |
| DWORD type = 0; | |
| LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, | |
| "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\", | |
| 0, | |
| KEY_QUERY_VALUE , | |
| &result); | |
| if (ERROR_SUCCESS == ret) { | |
| //scope_exit RegCloseKey(result); | |
| ret = RegQueryValueEx(result, "ProductName", 0, &type, data, &length); | |
| if (ERROR_SUCCESS == ret) { | |
| value = (char*)data; | |
| ZeroMemory(data, MAX_PATH); | |
| length = MAX_PATH; | |
| type = 0; | |
| //下面这句 死活返回2。。。肿么办。。。 | |
| ret = RegQueryValueEx(result, "CSDVersion", 0, &type, data, &length); | |
| if (ERROR_SUCCESS == ret) { | |
| return value + " " + (char*)data; | |
| } | |
| } | |
| } | |
| return ""; | |
| } | |
| int main() | |
| { | |
| printf("OS Information:%s", getOSInfo().c_str()); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment