after some time of pure C# experience, i thought it was time to check and refresh my old,dusty and little C abillities. this is a project, i had almost finished some time before, but lost all the files due to format.
ok here is what it does :
it infinitely checks all running processes whether your specified .exe is running. if it is not, it starts it.
that's it.
/* ProcessSitter, coded by usch
Infinitely checks all running processes
whether the defined exe is running.
If not, starts it.
usage: ps.exe <processname>
*/
#include <stdio.h>
#include <windows.h>
#include <Psapi.h>
int main(int argc, char *argv[])
{
void usage(void);
void mainFunction(char *arg);
if(argc!=2)
usage();
else
mainFunction(argv[1]);
}
void mainFunction(char *arg)
{
int x,returned;
char module[100];
HANDLE hProcess;
char name[200];
HMODULE modules;
DWORD prozesse[60],bytesReturned,moduleBytesReturned;
EnumProcesses(prozesse,sizeof(prozesse),&bytesReturned);
returned = bytesReturned/sizeof(DWORD);
for(x=0;x<returned;x++)
{
if((hProcess=OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,prozesse[x]))==0)
continue;
else
if((EnumProcessModules(hProcess,&modules,sizeof(modules),&moduleBytesReturned))==0)
continue;
else
if((GetModuleBaseName(hProcess,modules,name,200))==0)
continue;
}
for(x=0;x<returned;x++)
{
if(prozesse[x]==*arg)
continue;
else
{
system(arg);
sleep(250);
mainFunction(arg);
}
}
system("PAUSE");
}
void usage()
{
printf("\nProcessSitter - code by usch\n++++++++++++++++++++++++++++\n usage:ps.exe <exefile>\n");
}
hope someone will find it useful as it is nothing big and nothing special.
have fun
usch

