Advertisement
timus221

Untitled

Mar 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void __stdcall ThreadFun1()
  6. {
  7. printf("Hi This is my first thread.\n");
  8. }
  9. int main()
  10. {
  11.  
  12. ThreadFun1();
  13.  
  14. ////===========================GetCurrentProcess();=======================
  15. HANDLE h = GetCurrentProcess();
  16. SetPriorityClass(h, HIGH_PRIORITY_CLASS);
  17. printf("%x\n", GetPriorityClass(h));
  18.  
  19.  
  20. ////============================SetPriorityClass();=======================
  21. STARTUPINFO Sinfo = { 0 };
  22. PROCESS_INFORMATION Pinfo = { 0 };
  23.  
  24. CreateProcess(TEXT("C:\\Windows\\notepad.exe"), NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &Sinfo, &Pinfo);
  25.  
  26. DWORD Prior = GetPriorityClass(Pinfo.hProcess); // pobieram prior procesu, na poczatku jest rowny 32 (czemu?)
  27. printf("PRIOR: %x\n", Prior);
  28.  
  29. SetPriorityClass(Pinfo.hProcess, BELOW_NORMAL_PRIORITY_CLASS); // ustawiam se taki prior, msdn mowi : 0x00004000
  30.  
  31. Prior = GetPriorityClass(Pinfo.hProcess); // pobieram zowu, teraz jest 16384, czyli sie zgadza z szesnastkowym 0x00004000
  32.  
  33. printf("PRIOR: %x\n", Prior);
  34.  
  35.  
  36. CloseHandle(Pinfo.hProcess);
  37. CloseHandle(Pinfo.hThread);
  38.  
  39.  
  40. ////============================CREATE_THREAD()===========================
  41. printf("Entered In Main\n");
  42. HANDLE hThread;
  43. HANDLE hThread2;
  44. DWORD threadID;
  45. DWORD threadID2;
  46. //
  47. hThread = CreateThread(
  48. NULL, // security attributes ( default if NULL )
  49. 0, // stack SIZE default if 0
  50. (LPTHREAD_START_ROUTINE)ThreadFun1, // Start Address
  51. NULL, // input data
  52. 0, // creational flag ( start if 0 )
  53. &threadID); // thread ID
  54. SetThreadPriority(hThread, 1);
  55. int prior1 = GetThreadPriority(hThread);
  56. //
  57.  
  58. hThread2 = CreateThread(
  59. NULL, // security attributes ( default if NULL )
  60. 0, // stack SIZE default if 0
  61. (LPTHREAD_START_ROUTINE)ThreadFun1, // Start Address
  62. NULL, // input data
  63. 0, // creational flag ( start if 0 )
  64. &threadID2); // thread ID
  65. SetThreadPriority(hThread2, 2);
  66. int prior2 = GetThreadPriority(hThread2);
  67.  
  68. printf("Priorytet pierwszego watku: %d\n", prior1);
  69. printf("Priorytet drugiego watku: %d\n", prior2);
  70. printf("Main is exiting\n");
  71. //
  72. CloseHandle(hThread);
  73. CloseHandle(hThread2);
  74. //_getch();
  75.  
  76.  
  77. ////============================CREATE_PROCESS()===========================
  78. STARTUPINFO si;
  79. PROCESS_INFORMATION pi;
  80.  
  81. ZeroMemory(&si, sizeof(si));
  82. si.cb = sizeof(si);
  83. ZeroMemory(&pi, sizeof(pi));
  84.  
  85. //// Start the child process.
  86. if (!CreateProcess(
  87. TEXT("c:\\WINDOWS\\system32\\calc.exe"), // No module name (use command line)
  88. NULL, // Command line
  89. NULL, // Process handle not inheritable
  90. NULL, // Thread handle not inheritable
  91. FALSE, // Set handle inheritance to FALSE
  92. 0, // No creation flags
  93. NULL, // Use parent's environment block
  94. NULL, // Use parent's starting directory
  95. &si, // Pointer to STARTUPINFO structure
  96. &pi) // Pointer to PROCESS_INFORMATION structure
  97. )
  98.  
  99. printf("CreateProcess failed (%d).\n", GetLastError());
  100. //return;
  101. //}
  102. //// Wait until child process exits.
  103. WaitForSingleObject(pi.hProcess, INFINITE);
  104. //// Close process and thread handles.
  105. CloseHandle(pi.hProcess);
  106. CloseHandle(pi.hThread);
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement