?
Solved

How to reset windows service when settings file changes

Posted on 2009-07-14
3
Medium Priority
?
836 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified 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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

762 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