473,769 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows service with a configuration file

I wrote [my first] a windows service in c# (applause) and now I want to
add the ability to edit its settings. Basically this service checks an
email account at certain intervals and forwards the emails to another
email address. I want to be able to configure how often it runs (it
uses a timer, so setting the interval for that timer is what I mean by
that statement) and what account to check and what email address to
send to.

Seems easy, right? Well, I created a Settings.settin gs file and
populated it with all my variables (incomingPopSer ver,
incomingPopUser name, incomingPopPass word, etc...) that the service sets
onStart, but then I realized that I don't know how to get a form to
read & write these values.

I figured the way to do this is to create another VS.NET Project (the
service was called "Emailer Service" so this would be called "Emailer")
and create a single form with a few textboxes and a "Save" button that
saves those values to the Email Service's Settings.settin gs and then
restarts the service using the ServiceControll er class.

And here come my questions for you:

1) How do I get this Emailer project to "see" the settings from the
Emailer Service and how, once it sees them, do I get it to write to
them.
2) Is this even the best way to go about it? Might there be a
better/smarter/cheaper way of doing this?

Did that make any sense?

Thank you in advance,
Noah

Dec 13 '06 #1
1 5449

Yes you want a separate application. Typically a windows service with
a UI will have one app which is the windows service itself and a
totally separate app which is the UI. The service runs whether or not
the UI is running.

For your situation, you don't need the two apps to actually talk to
each other, they just need to share the same config file. Don't use
the Setings stuff--that's for preset application configuration and not
user configurable data. Instead use a custom file, most likely XML,
and put it in a standard location that both can find (suggest
Environment.Spe cialFolders.Com monApplicationD ata as the root). You'll
want to have a dll that both apps share in common for reading/writing
the XML file in order to not have duplicated code.

When the UI changes the config file, you can use ServiceControll er to
restart the service from the UI app. Or you can use a
FileSystemWatch er in the service to watch the config file and
auto-reload when it changes (be sure to have a little delay to be sure
the UI is done writing changes before you reload).

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 12 Dec 2006 18:22:51 -0800, no************* @gmail.com wrote:
>I wrote [my first] a windows service in c# (applause) and now I want to
add the ability to edit its settings. Basically this service checks an
email account at certain intervals and forwards the emails to another
email address. I want to be able to configure how often it runs (it
uses a timer, so setting the interval for that timer is what I mean by
that statement) and what account to check and what email address to
send to.

Seems easy, right? Well, I created a Settings.settin gs file and
populated it with all my variables (incomingPopSer ver,
incomingPopUse rname, incomingPopPass word, etc...) that the service sets
onStart, but then I realized that I don't know how to get a form to
read & write these values.

I figured the way to do this is to create another VS.NET Project (the
service was called "Emailer Service" so this would be called "Emailer")
and create a single form with a few textboxes and a "Save" button that
saves those values to the Email Service's Settings.settin gs and then
restarts the service using the ServiceControll er class.

And here come my questions for you:

1) How do I get this Emailer project to "see" the settings from the
Emailer Service and how, once it sees them, do I get it to write to
them.
2) Is this even the best way to go about it? Might there be a
better/smarter/cheaper way of doing this?

Did that make any sense?

Thank you in advance,
Noah
Dec 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12307
by: SP | last post by:
Please advice. I am not familiar with the concepts of windows service. I am trying to access a xml configuration file from windows service. But it is failing. configuration file is in the same directory from where I install windows service. I dont want to give an absolute path to the location of file. When I try to start windows service, it is expecting the XML file to be in c:\windows\system32\. Please let me know whether there is a...
6
2049
by: Dean R. Henderson | last post by:
I have a DTS Package I am able to execute successfully from a Windows Form application, but I cannot get this to work from an ASP.NET Web Service, although the Web Service impersonates the same user the Windows Form runs under. When I run the Web Service, I make a call to "System.Security.Principal.WindowsIdentity.GetCurrent().Name" and this verifies the user-id is the same account I am logged onto when I successfully run my Windows...
5
8475
by: Brian Patrick | last post by:
I have an application model which will consist of a front-end configuration application, which needs to control the state of a back-end vb.net windows service (which is the component that does all the work). Think of this in the same manner as say microsoft management console and the w3svc (inetinfo) service. What should the standard communication protocol be between the configuration app and the service in this model? For example,...
2
2460
by: Trevor | last post by:
Argh! This problem is driving me nuts! Can you help? In November of 2003, I installed a web service on Windows Server 2003 built in VB.NET for v1.1.4322 of the framework. It contains a timer (System.Timers.Timer) which has an interval of 24 hours. Actually, it reads a time like 2AM out of the config file, and calculates the time between the start of the service to 2AM, and sets the timer. When the timer expires, it re-reads the...
4
22542
by: PeterW | last post by:
I have a Windows service that needs to get some values from a config file. I place the config file for the service in the System32 directory. I do not get the values using the usual ConfigurationSettings.AppSettings Any tips please cheers -- PeterW
4
4182
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
2
14258
by: Olegus | last post by:
I have Windows service MyService, that reads some settings from MyService.exe.config file via ConfigurationManager.AppSettings. I tried to write small WinForm frontend app(called it Manager.exe) to manage settings of MyService, but have problems with accessing MyService.exe.config from Manager app. I am getting this error: "System.Configuration.ConfigurationElement.this' is inaccessible due to its protection level"
5
3307
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
1
2087
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding, endpoint etc. programmatically in the Program.cs file. Any idea what I might be doing wrong? Cheers,
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.