Solved

How to reset windows service when settings file changes

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

733 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