Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TimeManager.cpp: Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include <ctime>
- #include <Windows.h>
- #include <TlHelp32.h>
- #include <vector>
- #include <UIAnimation.h>
- #include <atlbase.h>
- #include <iostream>
- #include <string>
- namespace TMgr
- {
- std::vector<std::wstring> badProcesses =
- {
- L"notepad.exe",
- };
- void killProcessesByName(const wchar_t* processName)
- {
- HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
- PROCESSENTRY32 entry;
- entry.dwSize = sizeof(entry);
- bool hasEntry = Process32First(snapshot, &entry);
- while (hasEntry)
- {
- if (wcscmp(processName, entry.szExeFile) == 0)
- {
- std::wcout << "Die! " << processName << std::endl;
- HANDLE process = OpenProcess(PROCESS_TERMINATE, 0, entry.th32ProcessID);
- if (process != NULL)
- {
- TerminateProcess(process, 0);
- CloseHandle(process);
- }
- }
- hasEntry = Process32Next(snapshot, &entry);
- }
- CloseHandle(snapshot);
- }
- void killProcesses()
- {
- for (size_t i = 0; i < badProcesses.size(); i++)
- {
- killProcessesByName(badProcesses[i].data());
- }
- }
- std::wstring getTabName()
- {
- HWND hwnd = FindWindowEx(NULL, NULL, L"Chrome_WidgetWin_1", NULL);
- CComQIPtr<IUIAutomation> uia;
- if (FAILED(uia.CoCreateInstance(CLSID_CUIAutomation)) || !uia)
- {
- return L"ERROR";
- }
- while (true)
- {
- if (!hwnd)
- {
- return L"ERROR";
- }
- if (!IsWindowVisible(hwnd))
- {
- continue;
- }
- CComPtr<IUIAutomationElement> root;
- if (FAILED(uia->ElementFromHandle(hwnd, &root)) || !root)
- {
- return L"Error";
- }
- CComPtr<IUIAutomationCondidtion> cond;
- uia->CreatePropertyCondition(UIA_ControlTypePropertyId, CComVariant(0xC354), &cond);
- return NULL;
- }
- }
- [[noreturn]]
- void start()
- {
- CoInitialize(NULL);
- while (true)
- {
- time_t rawTime;
- time(&rawTime);
- tm timeInfo;
- localtime_s(&timeInfo, &rawTime);
- int weekday = timeInfo.tm_wday;
- int hour = timeInfo.tm_hour;
- if (weekday >= 1 && weekday <= 5 && hour >= 7 && hour <= 23)
- {
- }
- killProcesses();
- Sleep(250);
- }
- }
- }
- int main()
- {
- TMgr::start();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement