Reputation: 9
I used the Win32 API to monitor the process and try to code a program that would block cmd when it ran. (I want to turn off cmd immediately when it is detected or disable it.)
But when I run it, cmd opens well (...)
What should I do? Do you have to do it the other way around?
while (true) {
BOOL hRes = Process32Next(hSnapShot, &pEntry);
if (hRes == FALSE)
break;
if (pEntry.th32ProcessID == ::GetCurrentProcessId())
continue;
wchar_t* pn = pEntry.szExeFile;//I think this part may be a bit wrong but I don't know how to fix it...
if (pn != L"cmd.exe")
continue;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pEntry.th32ProcessID);
if (hProc) {
// 죽여버려!!!!
if (TerminateProcess(hProc, 0)) {
unsigned long nCode;
GetExitCodeProcess(hProc, &nCode);
}
CloseHandle(hProc);
return 1;
}
}
what should I do? If this qestion doesn’t have enough inforamation, ask me again about that please.
Upvotes: 0
Views: 52
Reputation: 12673
If you want to compare strings in C you can't do this by ==
. This will compare the addresses of the strings.
Use a function of the strcmp()
-family to compare the contents of the strings.
N.B.: This is a big problem also in other languages, for example Java or C#.
Upvotes: 1