Link to home
Start Free TrialLog in
Avatar of mohantyd
mohantydFlag for India

asked on

How to reset windows service when settings file changes

I have a windows service which watch a folder for arrival of new files.
windows service take this foldrrs path from a settings file .
When some one modify setting file how to reset windows service to watch diferent folder mentioned in settings file?

i have called this watcher  in OnStart method.
Code will be much appreciated
Avatar of flob9
flob9
Flag of France image

You can search this way :

http://www.codeproject.com/KB/system/CServiceWrapper.aspx

(OpenSCManager, OpenService,  ControlService, ...)
ASKER CERTIFIED SOLUTION
Avatar of flob9
flob9
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DanRollins
Normally, some process would need to communicate with the service to tell it to re-read its settings file and take appropriate action. This could be done through any sort of IPC mechanism, TCP, named pipe, etc.
Or... here's an idea: It could monitor for changes in its settings file. When it has been modified, it could automatically take action.
The simplest solution might be to simply stop the service and restart it. For instance, this pair of command lines would do it:
     net stop MyService
     net start MyService