Solved

How to reset windows service when settings file changes

Posted on 2009-07-14
3
830 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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 keystrokes in Netbeans IDE 8.0 for Windows.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now