Advertisement
Guest User

tmgr

a guest
Jun 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. // TimeManager.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
  2. //
  3.  
  4. #include <ctime>
  5. #include <Windows.h>
  6.  
  7. #include <TlHelp32.h>
  8. #include <vector>
  9.  
  10. #include <UIAnimation.h>
  11. #include <atlbase.h>
  12.  
  13. #include <iostream>
  14. #include <string>
  15.  
  16. namespace TMgr
  17. {
  18.     std::vector<std::wstring> badProcesses =
  19.     {
  20.         L"notepad.exe",
  21.     };
  22.  
  23.     void killProcessesByName(const wchar_t* processName)
  24.     {
  25.         HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
  26.  
  27.         PROCESSENTRY32 entry;
  28.         entry.dwSize = sizeof(entry);
  29.  
  30.         bool hasEntry = Process32First(snapshot, &entry);
  31.  
  32.         while (hasEntry)
  33.         {
  34.             if (wcscmp(processName, entry.szExeFile) == 0)
  35.             {
  36.                 std::wcout << "Die! " << processName << std::endl;
  37.                 HANDLE process = OpenProcess(PROCESS_TERMINATE, 0, entry.th32ProcessID);
  38.                 if (process != NULL)
  39.                 {
  40.                     TerminateProcess(process, 0);
  41.                     CloseHandle(process);
  42.                 }
  43.             }
  44.  
  45.             hasEntry = Process32Next(snapshot, &entry);
  46.  
  47.         }
  48.  
  49.         CloseHandle(snapshot);
  50.     }
  51.  
  52.     void killProcesses()
  53.     {
  54.         for (size_t i = 0; i < badProcesses.size(); i++)
  55.         {
  56.             killProcessesByName(badProcesses[i].data());
  57.         }
  58.     }
  59.  
  60.     std::wstring getTabName()
  61.     {
  62.         HWND hwnd = FindWindowEx(NULL, NULL, L"Chrome_WidgetWin_1", NULL);
  63.        
  64.         CComQIPtr<IUIAutomation> uia;
  65.         if (FAILED(uia.CoCreateInstance(CLSID_CUIAutomation)) || !uia)
  66.         {
  67.             return L"ERROR";
  68.         }
  69.  
  70.         while (true)
  71.         {
  72.             if (!hwnd)
  73.             {
  74.                 return L"ERROR";
  75.             }
  76.  
  77.             if (!IsWindowVisible(hwnd))
  78.             {
  79.                 continue;
  80.             }
  81.  
  82.             CComPtr<IUIAutomationElement> root;
  83.             if (FAILED(uia->ElementFromHandle(hwnd, &root)) || !root)
  84.             {
  85.                 return L"Error";
  86.             }
  87.  
  88.             CComPtr<IUIAutomationCondidtion> cond;
  89.             uia->CreatePropertyCondition(UIA_ControlTypePropertyId, CComVariant(0xC354), &cond);
  90.             return NULL;
  91.         }
  92.     }
  93.  
  94.     [[noreturn]]
  95.     void start()
  96.     {
  97.  
  98.         CoInitialize(NULL);
  99.  
  100.         while (true)
  101.         {
  102.             time_t rawTime;
  103.             time(&rawTime);
  104.  
  105.             tm timeInfo;
  106.             localtime_s(&timeInfo, &rawTime);
  107.  
  108.             int weekday = timeInfo.tm_wday;
  109.             int hour = timeInfo.tm_hour;
  110.  
  111.             if (weekday >= 1 && weekday <= 5 && hour >= 7 && hour <= 23)
  112.             {
  113.  
  114.             }
  115.             killProcesses();
  116.  
  117.             Sleep(250);
  118.         }
  119.  
  120.     }
  121. }
  122.  
  123. int main()
  124. {
  125.     TMgr::start();
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement