service to periodically run another program

I want to write a service that will run a program after a period.
I have been following some sample service codes on MSDN.

Any pointers?
Use CreateThread to start your timer. Give it the number of milliseconds to wait and the path to your program.
In your timer use Sleep to wait and then use system call to start that program: System("path\filename.exe");
According to https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948
in which function should i write CreateThread
This is how you create a thread in window:

1
2
//use this to start the thread
HANDLE childHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&child, 0, 0, 0);


1
2
3
4
5
6
DWORD child(LPVOID lpParameter) // your thread
{
    //do stuff

    return 0;
}
Oh yes, you mention doing it periodically. In this case just put everything in your child thread in while loop: while(1){/*your code*/}
I suppose zoran404 gave you the literal solution to your question, but is there any reason you're not just using the Task Scheduler service that is already running on the machine? The function to add a task to the queue is 'NetScheduleJobAdd()': http://msdn.microsoft.com/en-us/library/windows/desktop/aa370614%28v=vs.85%29.aspx .

To run the job periodically you would set the 'Flags' field of the 'AT_INFO' struct to 'JOB_RUN_PERIODICALLY': http://msdn.microsoft.com/en-us/library/windows/desktop/aa370248(v=vs.85).aspx .
Here's a pointer: 0xa12cf17c50
Topic archived. No new replies allowed.