My intention is that you can not run a certain application (prueba.exe) on a computer with windows. That equipment is usually always on and with my program running, and with the screen locked, so other users can enter. The application checks the processes that are in memory and, if resident, "prueba.exe" kills the process. This works fine when I'm in my session (being an administrator) and I open the program "prueba.exe" and it kills it, it also works fine when I open the program "prueba.exe" from my same session but launching it using runes with another user ( does not have privileges). The problem comes when another user logs in with their unprivileged user (my admin session and my program is still open) and that user runs the so-called "test.exe", so my application does not kill the process, I do not understand why.
In summary, my application kills the process from my session but if another user without admin logs in and runs the "prueba.exe" it allows you to execute it and my application does not kill the process.
I put the code:
#include <stdio.h>
#include <windows.h>
#include <Tlhelp32.h>
#include <psapi.h>
void main(void)
{
while (1)
{
HANDLE CProc;
PROCESSENTRY32 process;
Sleep(1);
CProc = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
Process32First(CProc,&process);
process.dwSize = sizeof(PROCESSENTRY32); //windows 10
while(Process32Next(CProc,&process))
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,(DWORD) process.th32ProcessID);
if(strcasecmp(process.szExeFile,"prueba.exe")==0)
{
printf("prueba.exe in memory");
TerminateProcess(hProcess,0);
}
}
CloseHandle(CProc);
}
}
Thank you very much in advance. (Win7)