Advertisement
cuonic

Windows Shit

Jul 13th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.97 KB | None | 0 0
  1. #define UNICODE
  2. #define _UNICODE
  3. //#define TESTING
  4. #include <windows.h>
  5. #include <wininet.h>
  6. #include <tlhelp32.h>
  7. #include <iostream>
  8. using namespace std;
  9. #pragma comment(lib,"ws2_32.lib")
  10. //ToDo: Special Dirs
  11. int QueryKey(HKEY hKey, LPTSTR Path, LPTSTR Value);
  12. struct SearchRegistry{
  13.     LPTSTR Key;
  14.     LPTSTR ValueName;
  15. };
  16. int main()
  17. {
  18.     TCHAR ComputerName[512] = {0}, UserName[512] = {0}, CPUName[512] = {0},
  19.         VendorIdentifier[512] = {0}, Country[512] = {0}, lpVolumeNameBuffer[512] = {0},
  20.         lpFileSystemNameBuffer[512] = {0},    szDrives[512] = {0},
  21.         lpProcessorName[512] = {0}, ProcessorRegistryPath[512] = {0},
  22.         NETPath[MAX_PATH] = {0}, NetVersion[11]=TEXT("v0.0");
  23.     char hostname[255], *IPAddress;
  24.     DWORD dwComputerNameSize=512, dwUserNameSize=512, dwSize=512, dwType, dwTotal, dwHours, dwMinutes, dwDays,
  25.         dwVolumeNameSize=512, dwVolumeSerialNumber, dwMaximumComponentLenght, dwFileSystemFlags,
  26.         dwFileSystemNameSize=512, dwProcessorIndex=0, dwProcessorNameLength=512, dwNetPathSize = 512;
  27.     HKEY hKey, hKey2;
  28.  
  29.     srand(GetTickCount());
  30.     try
  31.     {
  32.  
  33. #if defined TESTING
  34.     wcout << TEXT("OS:");
  35. #endif
  36.  
  37.     OSVERSIONINFOEX osVI = {0};
  38.     osVI.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  39.     if (GetVersionEx((LPOSVERSIONINFO)&osVI))
  40.     {
  41.         if( osVI.dwMajorVersion==4 && osVI.dwMinorVersion == 0 )
  42.         {    
  43.             if ( osVI.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
  44.             {
  45.                 wcout << TEXT("95");
  46.             }
  47.             if ( osVI.dwPlatformId == VER_PLATFORM_WIN32_NT )    
  48.             {
  49.                 wcout << TEXT("NT");
  50.             }
  51.         }
  52.         else if ( osVI.dwMajorVersion == 4 && osVI.dwMinorVersion == 10 )
  53.         {
  54.             wcout << TEXT("98");
  55.         }
  56.         else if ( osVI.dwMajorVersion == 4 && osVI.dwMinorVersion == 90 )
  57.         {
  58.             wcout << TEXT("ME");
  59.         }
  60.         else if ( osVI.dwMajorVersion == 5 && osVI.dwMinorVersion == 0 )
  61.         {
  62.             wcout << TEXT("2000");
  63.         }
  64.         else if ( osVI.dwMajorVersion == 5 && osVI.dwMinorVersion == 1 )
  65.         {
  66.             wcout << TEXT("XP");
  67.         }
  68.         else if ( osVI.dwMajorVersion == 5 && osVI.dwMinorVersion == 2 )
  69.         {
  70.             wcout << TEXT("2003");
  71.         }
  72.         else if ( osVI.dwMajorVersion == 6 && osVI.dwMinorVersion == 0 )
  73.         {
  74.             wcout << TEXT("Vista");
  75.         }
  76.         else if ( osVI.dwMajorVersion == 6 && osVI.dwMinorVersion == 1 )
  77.         {
  78.             wcout << TEXT("7");
  79.         }
  80.         else
  81.         {
  82.             wcout <<osVI.dwMajorVersion << "." << osVI.dwMinorVersion;
  83.         }
  84.  
  85.     }
  86.     wcout << TEXT(" ") << osVI.szCSDVersion
  87.         << TEXT(" (") << osVI.dwMajorVersion << TEXT(".") << osVI.dwMinorVersion << TEXT(")")
  88.         << TEXT(" SP") << osVI.wServicePackMajor << TEXT(".") << osVI.wServicePackMinor
  89.         << TEXT(" PlatformId:") << osVI.dwPlatformId
  90.         << TEXT(" Build:") << osVI.dwBuildNumber;
  91.  
  92. #if defined TESTING
  93.     wcout << endl << endl;
  94. #endif
  95.  
  96.     if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\.NETFramework"),
  97.         0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)
  98.     {
  99.         if(RegQueryValueExW(hKey, TEXT("InstallRoot"), NULL, 0, (LPBYTE)NETPath,
  100.             &dwNetPathSize) == ERROR_SUCCESS)
  101.         {
  102.             WIN32_FIND_DATA FoundFile;
  103.             HANDLE FileHandle;
  104.             //wcout << NETPath << endl;
  105.             lstrcat(NETPath, TEXT("\\v*.*"));
  106.             FileHandle = FindFirstFile(NETPath, &FoundFile);
  107.             do
  108.             {
  109.                 //FoundFile.cFileName[4] = 0;
  110.                 //wcout << FoundFile.cFileName << endl;
  111.                 if(lstrcmp(FoundFile.cFileName, NetVersion))//FoundFile.cFileName[1] > NetVersion[1] || FoundFile.cFileName[3] > NetVersion[3])
  112.                 {
  113.         lstrcpy(NetVersion, FoundFile.cFileName);
  114.                 }
  115.             }while(FindNextFile(FileHandle, &FoundFile));
  116.             FindClose(FileHandle);
  117.         }
  118.  
  119.         RegCloseKey(hKey);
  120.     }
  121. #if defined TESTING
  122.     wcout << TEXT("Installed .NET Version: ");
  123. #else
  124.     wcout << TEXT(";");
  125. #endif
  126.  
  127.     wcout << NetVersion;
  128.  
  129. #if defined TESTING
  130.     wcout << endl << endl;
  131. #endif
  132.  
  133. #if defined TESTING
  134.     wcout << TEXT("Uptime:") << endl;
  135. #else
  136.     wcout << TEXT(";");
  137. #endif
  138.  
  139.     /*
  140.     UPTIME
  141.     */
  142.     dwTotal = GetTickCount() / 1000;
  143.     dwDays = dwTotal / 86400;
  144.     dwHours = (dwTotal % 86400) / 3600;
  145.     dwMinutes = ((dwTotal % 86400) % 3600) / 60;
  146.     wcout << TEXT("Days: ") << dwDays
  147.          << TEXT("\tHours: ") << dwHours
  148.          << TEXT("\tMin: ") << dwMinutes;
  149.  
  150. #if defined TESTING
  151.     wcout << endl << endl;
  152. #endif
  153.  
  154.     SYSTEMTIME lpSystemTime;
  155.  
  156. #if defined TESTING
  157.     wcout << TEXT("UTC Time:") << endl;
  158. #else
  159.     wcout << TEXT(";");
  160. #endif
  161.  
  162.     /*
  163.     DATETIME
  164.     */
  165.     GetSystemTime(&lpSystemTime);
  166.     wcout << lpSystemTime.wDay << TEXT(".") << lpSystemTime.wMonth << TEXT(".") << lpSystemTime.wYear
  167.          << TEXT(" ") << lpSystemTime.wHour
  168.          << TEXT(":") << lpSystemTime.wMinute << TEXT(":") <<lpSystemTime.wSecond;
  169.  
  170. #if defined TESTING
  171.     wcout << endl << endl;
  172. #else
  173.     wcout << TEXT(";");
  174. #endif
  175.     /*
  176.     INTERNET CONNECTION TYPE
  177.     */
  178.     DWORD dwConnectionType;
  179.     if(InternetGetConnectedState(&dwConnectionType, 0))
  180.     {
  181.         wcout << dwConnectionType;
  182.     }
  183.     else
  184.         wcout << TEXT("Error:") << GetLastError();
  185.  
  186. #if defined TESTING
  187.     wcout << endl << endl;
  188. #else
  189.     wcout << TEXT(";");
  190. #endif
  191.  
  192.     GetComputerName(ComputerName, &dwComputerNameSize);
  193.     GetUserName(UserName, &dwUserNameSize);
  194.     GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SLANGUAGE, Country, 512);
  195.     wcout << TEXT("PCName: ") << ComputerName
  196.          << TEXT("\tUser: ") << UserName
  197.          << TEXT("\tLanguage: ") << Country;
  198.  
  199. #if defined TESTING
  200.     wcout << endl << endl << TEXT("Drives:") << endl;
  201. #else
  202.     wcout << TEXT(";");
  203. #endif
  204.     /*
  205.     DRIVE INFO
  206.     */
  207.     if(GetLogicalDriveStrings( MAX_PATH, szDrives ))  
  208.     {  
  209.         LPTSTR lptszOneDrive = szDrives;  
  210.         while(*lptszOneDrive)  
  211.         {  
  212.             if(lptszOneDrive[0] == 'A')
  213.             {
  214.                 lptszOneDrive += lstrlen( lptszOneDrive ) + 1;
  215.                 continue;
  216.             }            
  217.  
  218.             if(GetVolumeInformation(lptszOneDrive, lpVolumeNameBuffer, dwVolumeNameSize, &dwVolumeSerialNumber,
  219.                 &dwMaximumComponentLenght, &dwFileSystemFlags, lpFileSystemNameBuffer, dwFileSystemNameSize))
  220.             {
  221.                 wcout << lptszOneDrive << TEXT("\t");
  222.                 wcout << TEXT("\tName:") <<lpVolumeNameBuffer
  223.          //<< TEXT("\tSerial:") <<dwVolumeSerialNumber<<endl
  224.          //<< TEXT("\tMaximal Filename length:") <<dwMaximumComponentLenght
  225.          << TEXT("\tFileSystem:") <<lpFileSystemNameBuffer
  226.          << TEXT("\t");
  227.  
  228.             }
  229.  
  230. #if defined TESTING
  231.             wcout << endl;
  232. #endif
  233.  
  234.             lptszOneDrive += lstrlen(lptszOneDrive) + 1;  
  235.         }
  236.     }
  237.  
  238. #if defined TESTING
  239.     wcout <<endl;
  240.     wcout << TEXT("CPU:") << endl;
  241. #else
  242.     wcout << TEXT(";");
  243. #endif
  244.  
  245.     /*
  246.     CPU
  247.     */
  248.     RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"),
  249.         0, 0, REG_OPTION_NON_VOLATILE,    KEY_READ, NULL, &hKey, 0);
  250.     if(hKey)
  251.     {
  252.         while(RegEnumKeyEx(hKey, dwProcessorIndex, lpProcessorName,
  253.             &dwProcessorNameLength, 0, 0, 0, 0) != ERROR_NO_MORE_ITEMS)
  254.         {
  255.             wcout << TEXT("\tCPU:") << lpProcessorName;
  256.             wsprintf(ProcessorRegistryPath, TEXT("%s\\%s"),
  257.                 TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"), lpProcessorName);
  258.             RegCreateKeyEx(HKEY_LOCAL_MACHINE, ProcessorRegistryPath, 0, 0, REG_OPTION_NON_VOLATILE,
  259.                 KEY_READ, NULL, &hKey2, 0);
  260.             if(RegQueryValueEx(hKey2, TEXT("VendorIdentifier"), NULL, &dwType,
  261.                 (LPBYTE)VendorIdentifier, &dwSize)==ERROR_SUCCESS && strlen((char*)VendorIdentifier))
  262.             {
  263.                 wcout << TEXT("\tBy: ") << VendorIdentifier;
  264.             }            
  265.             dwSize = 512;
  266.             if(RegQueryValueEx(hKey2, TEXT("ProcessorNameString"), NULL, &dwType,
  267.                 (LPBYTE)CPUName, &dwSize)==ERROR_SUCCESS && strlen((char*)CPUName))
  268.             {
  269.                 wcout << TEXT("\tName: ") << CPUName;
  270.             }
  271.  
  272.             dwProcessorIndex++;
  273.             dwProcessorNameLength = 512;
  274.         }
  275.  
  276.     }
  277.     RegCloseKey(hKey);
  278.     RegCloseKey(hKey2);
  279.  
  280. #if defined TESTING    
  281.     wcout << endl << endl;
  282.     wcout << TEXT("Local IP:") << endl;
  283. #else
  284.     wcout << TEXT(";");
  285. #endif
  286.  
  287.     /*
  288.     LOCAL IPs
  289.     */
  290.     PHOSTENT hostinfo;
  291.     WSADATA wsadata;
  292.     WSAStartup(MAKEWORD(2,2), &wsadata);
  293.     if(gethostname(hostname, sizeof(hostname)) == 0)
  294.     {
  295.         if((hostinfo = gethostbyname(hostname)) != NULL)
  296.         {
  297.             while(*hostinfo->h_addr_list)
  298.             {
  299.                 IPAddress = (char*)inet_ntoa ((*(struct in_addr *)*hostinfo->h_addr_list));
  300.                 cout << IPAddress;
  301.                 wcout << TEXT(",");
  302.                 *hostinfo->h_addr_list++;
  303.             }        
  304.         }
  305.  
  306.     }
  307.     WSACleanup();
  308.  
  309. #if defined TESTING
  310.     wcout << endl;
  311. #endif
  312.  
  313.     /*
  314.     RAM INFO
  315.     */
  316.     MEMORYSTATUS memstat;
  317.     GlobalMemoryStatus(&memstat);
  318.  
  319. #if defined TESTING
  320.     wcout << TEXT("Memory:") << endl;
  321. #else
  322.     wcout << TEXT(";");
  323. #endif
  324.  
  325.     wcout << memstat.dwTotalPhys/(1024 * 1024) << TEXT("mb")
  326.          << TEXT("\tIn Use:") << memstat.dwMemoryLoad << TEXT("%");
  327.  
  328. #if defined TESTING
  329.     wcout << endl << endl;
  330. /*#else
  331.     wcout << TEXT(";");*/
  332. #endif
  333.  
  334.     /*
  335.     INSTALLED SOFTWARE
  336.     */
  337.     HKEY hTestKey;
  338.     SearchRegistry Cool[] =
  339.         {
  340.             //{TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths"), TEXT("")},
  341.             {TEXT("SOFTWARE\\"), TEXT("")},
  342.             0
  343.         };
  344.  
  345.     for(int i = 0; Cool[i].Key; i++)
  346.     {
  347.         HKEY HKeys[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, 0};
  348.         for(int j = 0; HKeys[j]; j++)
  349.         {
  350.             wcout << TEXT(";Enumerating ") << HKeys[j] << TEXT("\\") << Cool[i].Key << endl;
  351.             if(RegOpenKeyEx(HKeys[j], Cool[i].Key, 0, KEY_READ, &hTestKey) == ERROR_SUCCESS)
  352.             {
  353.                 QueryKey(hTestKey, Cool[i].Key, Cool[i].ValueName, Cool[i].WTE);
  354.                 RegCloseKey(hTestKey);
  355.             }
  356.         }
  357.     }
  358.  
  359. #if defined TESTING
  360.     wcout << endl << endl;
  361. #endif
  362.  
  363.     /*
  364.     PRCESSLIST
  365.     */
  366.     HANDLE hProcessSnap;
  367.     PROCESSENTRY32 pe32;
  368.  
  369. #if defined TESTING
  370.     wcout << TEXT("Process list:") << endl;
  371. #else
  372.     wcout << TEXT(";");
  373. #endif
  374.  
  375.     hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  376.     pe32.dwSize = sizeof(PROCESSENTRY32);
  377.  
  378.     if (Process32First(hProcessSnap, &pe32))
  379.     {
  380.         //Loop Through Processnames In Hunt Of The One We Are Looking For
  381.         do
  382.         {
  383.             wcout << pe32.szExeFile << TEXT(",");
  384.         }while(Process32Next(hProcessSnap, &pe32));
  385.  
  386.     }
  387.     CloseHandle(hProcessSnap);
  388.  
  389.     wcout << TEXT(";");
  390.     /*
  391.     SPEEDTEST
  392.     */
  393.     DWORD dwStartTime = 0, dwEndTime = 0, dwFileSize = 0, dwDownSpeed = 0, dwUDTFReturn = 0;
  394.     TCHAR path[MAX_PATH] = {0};
  395.     HANDLE hFile;
  396.     LPTSTR szBigFiles[] =
  397.         {
  398.             TEXT("http://download.thinkbroadband.com/10MB.zip"),
  399.             TEXT("http://google.com"),
  400.             0
  401.         };
  402.  
  403.     /*GetTempPath(MAX_PATH - lstrlen(TEXT("speedtest.bin")), path);
  404.     lstrcat(path, TEXT("speedtest.bin"));*/
  405.  
  406.     LPTSTR pLastFile = szBigFiles[3], FileToUse;
  407.  
  408.     //Download 2 files in hope to get a more accurate estimate
  409.     for(int k = 0; k < 2; k++)
  410.     {
  411.         do
  412.         {
  413.             FileToUse = szBigFiles[rand() % 6];
  414.         }while(FileToUse == pLastFile);
  415.         pLastFile = FileToUse;
  416.  
  417.         dwStartTime = GetTickCount();        
  418.         if((dwUDTFReturn = URLDownloadToCacheFile(0, FileToUse, path, MAX_PATH, 0, 0)) != S_OK)
  419.         {
  420.             wcout << GetLastError() << TEXT(":") << dwUDTFReturn << endl;
  421.             continue;
  422.         }
  423.         dwEndTime = GetTickCount();
  424.  
  425. wcout << path << endl;
  426.         hFile = CreateFile(path, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  427.         if(hFile == INVALID_HANDLE_VALUE)
  428.         {
  429.             wcout << GetLastError() << endl;
  430.             continue;
  431.         }
  432.         dwFileSize = GetFileSize(hFile, 0) / (1024*1024);
  433.         CloseHandle(hFile);
  434.  
  435.         DeleteFile(path);
  436.         dwDownSpeed = (dwEndTime - dwStartTime) / 1000;
  437.         wcout << FileToUse << TEXT(" (") << dwFileSize << TEXT("mb) downloaded in ")
  438.             << dwDownSpeed << TEXT("sec! ");
  439.     }
  440.     wcout << TEXT(";");
  441.  
  442.     }
  443.     catch(...)
  444.     {
  445.         wcout << TEXT("An exception occured. Meaning I suck at coding,") << endl;
  446.     }
  447. */
  448.     return 0;
  449. }
  450. #define MAX_KEY_LENGTH 255
  451. #define MAX_VALUE_NAME 512
  452. int QueryKey(HKEY hKey, LPTSTR Path, LPTSTR ValueName)
  453. {
  454.     TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
  455.     DWORD    cbName;     // size of name string
  456.     TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
  457.     DWORD    cchClassName = MAX_PATH;  // size of class string
  458.     DWORD    cSubKeys=0;     // number of subkeys
  459.     DWORD    cbMaxSubKey;    // longest subkey size
  460.     DWORD    cchMaxClass;    // longest class string
  461.     DWORD    cValues;    // number of values for key
  462.     DWORD    cchMaxValue;    // longest value name
  463.     DWORD    cbMaxValueData;  // longest value data
  464.  
  465.     FILETIME ftLastWriteTime;  // last write time
  466.  
  467.     DWORD i, retCode;
  468.  
  469.     TCHAR  achValue[MAX_VALUE_NAME];
  470.     DWORD cchValue = MAX_VALUE_NAME;
  471.     TCHAR  achValue_[512];
  472.     DWORD cchValue_ = 512;
  473.     // Get the class name and the value count.
  474.     retCode = RegQueryInfoKey(
  475.   hKey,    // key handle
  476.   achClass,    // buffer for class name
  477.   &cchClassName,     // size of class string
  478.   NULL,    // reserved
  479.   &cSubKeys,     // number of subkeys
  480.   &cbMaxSubKey,    // longest subkey size
  481.   &cchMaxClass,    // longest class string
  482.   &cValues,    // number of values for this key
  483.   &cchMaxValue,    // longest value name
  484.   &cbMaxValueData,  // longest value data
  485.   0,   // security descriptor
  486.   0);  // last write time
  487.  
  488.     if (cValues)
  489.     {
  490.   //printf( "\nNumber of values: %d\n", cValues);
  491. //        wcout << TEXT("|") << cValues << TEXT("|");
  492.   for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
  493.   {
  494.     cchValue_ = 512; cchValue = MAX_VALUE_NAME;
  495.     //achValue[0] = '\0'; achValue_[0] = '\0';
  496.     retCode = RegEnumValue(hKey, i,
  497.     achValue,
  498.     &cchValue,
  499.     NULL,
  500.     NULL,
  501.     (LPBYTE)achValue_,
  502.     &cchValue_);
  503.  
  504.     if (retCode == ERROR_SUCCESS )
  505.     {
  506.     wcout << achValue << TEXT(" -> ") << achValue_;
  507.     }
  508.             wcout << TEXT(",");
  509.   }
  510.  
  511.     }
  512.  
  513. END:
  514.     return 0;
  515. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement