service to periodically run another program

Dec 20, 2014 at 10:57am
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?
Dec 20, 2014 at 5:26pm
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");
Dec 24, 2014 at 10:47pm
According to https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948
in which function should i write CreateThread
Dec 26, 2014 at 1:45pm
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;
}
Dec 26, 2014 at 1:48pm
Oh yes, you mention doing it periodically. In this case just put everything in your child thread in while loop: while(1){/*your code*/}
Dec 26, 2014 at 5:05pm
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 .
Dec 27, 2014 at 11:08pm
Here's a pointer: 0xa12cf17c50
Topic archived. No new replies allowed.