hi i need help with this script below it should terminate a process liek if you type in "ROBLOX"(a game i play) i want it to terminate it so heres the script
#include <iostream>
#include <Windows.h>
#include <cstdlib>
#include <string>
#include <TlHelp32.h>
#include <tchar.h>
using namespace std;
string UserInput;
int main()
{
cout << "What process do you want to kill";
cin >> UserInput;
HWND win = FindWindow(NULL, UserInput);
DWORD id;
GetWindowThreadProcessId(win, &id);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
int termin = TerminateProcess(hProcess, 0);
if (termin > 0) {
clog << "closed roblox";
}
else {
cerr << "Cannot close roblox";
}
cin.get();
return NULL;
}
When there is a problem with your code, you need to provide as much information as possible to those who might help. Otherwise, it's obvious you aren't willing to put any effort into the thread, so why should anyone else?
The Windows API is C. You can't feed a C++ string to a C API.
ya i dont know how to provide alot of information about it but suppose you type in ROBLOX ( game window name ) then it should terminate the process and the error is in "hwnd win = FindWindow(NULL, UserInput)" the word "UserInput" is underlined
Again, the Windows API is C. You can't feed a C++ string to a C API.
HWND win = FindWindow(NULL, UserInput.c_str());
ya i dont know how to provide alot of information
Well, for instance, if something doesn't compile, your compiler gives you a reason why. Copy-and-pasting the reason(s) in your post would be a good start.