Advertisement
Guest User

Untitled

a guest
Aug 9th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. char* GetProcessPath(DWORD ProcessId)
  2. {
  3.     char* ptr;
  4.     char buffer[MAX_PATH];
  5.  
  6.     MessageBox(NULL, "ProcessPath() called", "Error", MB_ICONERROR);
  7.     HANDLE hProcess;
  8.  
  9.     hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessId);
  10.  
  11.     if (GetModuleFileNameEx(hProcess, NULL, buffer, sizeof(buffer) / sizeof(char)))
  12.     {
  13.         ptr = buffer;
  14.     }
  15.     else {
  16.         ptr = "\0";
  17.         MessageBox(NULL, "Failed to get process path.", "Error", MB_ICONERROR);
  18.     }
  19.  
  20.     return ptr;
  21. }
  22.  
  23. DWORD WINAPI MainThread(PVOID p)
  24. {
  25.     MessageBox(NULL, "Main thread called.", "Information", MB_ICONINFORMATION);
  26.    
  27.     char* path = GetProcessPath(GetProcessesByName("Spotify.exe"));
  28.     MessageBox(NULL, path, "Information", MB_ICONINFORMATION);
  29.     // Calling GetProcessPath() here crashes the slave process cause of using string without runtime library
  30.  
  31.     bool MAIN_THREAD = true;
  32.  
  33.     while (MAIN_THREAD)
  34.     {
  35.  
  36.         if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
  37.         {
  38.             MessageBox(NULL, "Main thread closed!", "Information", MB_ICONINFORMATION);
  39.             MAIN_THREAD = false;
  40.         }
  41.  
  42.         Sleep(1);
  43.  
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement