Advertisement
Guest User

FullNamer

a guest
Jul 18th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <conio.h>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7.  
  8. #define BUFFER_SIZE 1024
  9.  
  10. #if defined(UNICODE) || defined(_UNICODE)
  11. #define tcout std::wcout
  12. #else
  13. #define tcout std::cout
  14. #endif
  15.  
  16. std::vector<std::wstring> Info;
  17.  
  18. void FillVector();
  19. void Greetings();
  20. void HandleKeys();
  21. void GetNameWindows();
  22. std::wstring GetRegSubKey(LPCWSTR subKeysPath, std::wstring surrentsubKeysPath);
  23. std::wstring TCHARToString(TCHAR someChar[]);
  24. LPWSTR ConvertToLPWSTR(const std::wstring& someString);
  25. std::wstring GetStringWithBitWindows();
  26. BOOL Is64BitWindows();
  27.  
  28. bool WorkDone = false;
  29.  
  30. int main( int argc, _TCHAR* argv[] )
  31. {
  32.     int code;
  33.     bool doWork = true;
  34.  
  35.     FillVector();
  36.  
  37.     while (doWork)
  38.     {
  39.         system("cls");
  40.  
  41.         Greetings();
  42.         HandleKeys();
  43.     }
  44. }
  45.  
  46. void FillVector()
  47. {
  48.     Info.push_back(L"Getter Full Name Windows OS");
  49.     Info.push_back(L" ");
  50.     Info.push_back(L"Press Escape to Exit Program");
  51.     Info.push_back(L"Press Enter to Execute Code");
  52. }
  53.  
  54. void Greetings()
  55. {
  56.     for(int i = 0; i < Info.size(); ++i)
  57.     {
  58.         std::wcout << Info[i] << std::endl;
  59.     }
  60. }
  61.  
  62. void HandleKeys()
  63. {
  64.     switch (_getch())
  65.     {
  66.     case 13:
  67.         if (WorkDone)
  68.         {
  69.             return;
  70.         }          
  71.  
  72.         try
  73.         {
  74.             GetNameWindows();
  75.         }
  76.         catch (const std::exception&)
  77.         {
  78.             std::cout << "Failed to read full name current system" << std::endl;
  79.         }
  80.        
  81.         break;
  82.     case 27:
  83.         exit(1);
  84.         break;
  85.     }
  86. }
  87.  
  88. void GetNameWindows()
  89. {
  90.     LPCWSTR spacer = L" ";
  91.     LPCWSTR subKeysPath = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  92.    
  93.     std::vector<std::wstring> subKeys;
  94.     subKeys.push_back(L"ProductName");
  95.     subKeys.push_back(L"CurrentBuild");
  96.     //subKeys.push_back(L"CSDVersion");
  97.     subKeys.push_back(L"BuildLabEx");
  98.     subKeys.push_back(L"ReleaseId");
  99.     subKeys.push_back(L"SystemRoot");
  100.  
  101.     std::wstring fullNameWindows;
  102.  
  103.    
  104.     Info.push_back(L" ");
  105.  
  106.     fullNameWindows = L"Operating System: " + GetRegSubKey(subKeysPath, subKeys[0]);
  107.     fullNameWindows += spacer + GetStringWithBitWindows();
  108.     fullNameWindows += L" (Build " + GetRegSubKey(subKeysPath, subKeys[1]) + L"),";
  109.     fullNameWindows += spacer + GetRegSubKey(subKeysPath, subKeys[2]);
  110.     fullNameWindows += spacer + GetRegSubKey(subKeysPath, subKeys[3]);
  111.  
  112.     Info.push_back(L"SystemRoot " + GetRegSubKey(subKeysPath, subKeys[4]));
  113.     Info.push_back(fullNameWindows);
  114.  
  115.     WorkDone = true;
  116. }
  117.  
  118. std::wstring GetRegSubKey(LPCWSTR subKeysPath, std::wstring surrentsubKeysPath)
  119. {
  120.     DWORD bufferSize = BUFFER_SIZE;
  121.     TCHAR tempoBuffer[BUFFER_SIZE];
  122.  
  123.     RegGetValue(HKEY_LOCAL_MACHINE, subKeysPath, ConvertToLPWSTR(surrentsubKeysPath), RRF_RT_ANY, NULL, tempoBuffer, &bufferSize);
  124.  
  125.     return TCHARToString(tempoBuffer);
  126. }
  127.  
  128. std::wstring TCHARToString(TCHAR someChar[])
  129. {
  130.     std::wstring tempo(someChar);
  131.     return tempo;
  132. }
  133.  
  134. LPWSTR ConvertToLPWSTR(const std::wstring& someString)
  135. {
  136.     LPWSTR ws = new wchar_t[someString.size() + 1];
  137.     std::copy(someString.begin(), someString.end(), ws);
  138.     ws[someString.size()] = 0;
  139.     return ws;
  140. }
  141.  
  142. std::wstring GetStringWithBitWindows()
  143. {
  144.     if (Is64BitWindows())
  145.     {
  146.         return L"64 bit";
  147.     }
  148.     return L"32 bit";
  149. }
  150.  
  151. BOOL Is64BitWindows()
  152. {
  153. #if defined(_WIN64)
  154.     return TRUE;  // 64-bit programs run only on Win64
  155. #elif defined(_WIN32)
  156.     // 32-bit programs run on both 32-bit and 64-bit Windows
  157.     // so must sniff
  158.     BOOL f64 = FALSE;
  159.     return IsWow64Process(GetCurrentProcess(), &f64) && f64;
  160. #else
  161.     return FALSE; // Win64 does not support Win16
  162. #endif
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement