I wrote a simple program that check if a program run (e.g. Notepad). The compiled program should start in the Windows Task-Scheduler. Problem is, when I run my program normal, it works. When I run in Task-Scheduler it works too when I use the option: "Only run if the user is logged in". But when I use the option: "Execute independently of the user login" it doesn't work. My program can'tt find anything running programs (my program run, I can see in Task-Manager).
My Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void write_status(int state);
int isRunning(LPCSTR test);
int ret_val = 0;
int main(void)
{
while(1)
{
if(kbhit()) if(getch() == ' ') return 0;
Sleep(500);
ret_val = isRunning("Unbenannt - Editor");
printf("STATUS: %i\r", ret_val);
write_status(ret_val);
}
}
void write_status(int state)
{
FILE *fp = fopen("V:/ARAMAM.txt", "w");
if(state)
fprintf(fp, "ACTIVE ");
else
fprintf(fp, "NOT ACTIVE");
fclose(fp);
}
int isRunning(LPCSTR test)
{
HWND hwnd;
hwnd = FindWindowA(NULL, test);
if (hwnd != 0) {
return 1;
}
else {
return 0;
}
}
In the dont working case no console window shows. For this case i wrote the output in a external file. The writing in file works. Only find the running program fail.
My settings in Task-Scheduler, it's in German, sorry: IMAGE
Can somebody help?
Umbrecht