Solved

How to reset windows service when settings file changes

Posted on 2009-07-14
3
833 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:mohantyd
  • 2
3 Comments
 
LVL 14

Expert Comment

by:flob9
ID: 24847392
You can search this way :

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

(OpenSCManager, OpenService,  ControlService, ...)
0
 
LVL 14

Accepted Solution

by:
flob9 earned 500 total points
ID: 24847405
You can also use a custom control code to ask a "hot reload" of the config file.

See : http://msdn.microsoft.com/en-us/library/ms682108%28VS.85%29.aspx

"Range 128 to 255

The service defines the action associated with the control code. The hService handle must have the SERVICE_USER_DEFINED_CONTROL access right."
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 24865830
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
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question