user1402643
user1402643

Reputation: 419

How to restart window service after a particular time

I am making a window service in VS2010 using c++ and want to know is there any way to restart the service after a particular time,actually i will let user to write restart time in an INI file and service should be able to restart at that time.any sample code or any api available???

Upvotes: 1

Views: 1588

Answers (3)

Ashwin
Ashwin

Reputation: 1960

You can use load and execute new child process using _execl.

Here is a simple code illustrating how I did open a Notepad++ instance:

#include <process.h>

int main(){
    _execl("C:\\Program Files\\Notepad++\\Notepad++.exe", "\\0");
    return 0;
}

This way you can have another process that will actually stop your current process and start your process again.

Upvotes: 3

Superman
Superman

Reputation: 3083

The StartService API can start a windows service and the ControlService API can stop a windows service.

Upvotes: 0

kenny
kenny

Reputation: 22334

Add a scheduled task to call a batch file that does

net stop servicename
net start servicename

Upvotes: 1

Related Questions