Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I have created a window service but i want it to make parameterised.

Sample code used is :
C#
protected override void OnStart(string[] args)
       {
           base.OnStart(args);
           string name = args[0];
           string text = args[1];

           FileStream fs = new FileStream(name, FileMode.OpenOrCreate, FileAccess.Write);
           StreamWriter m_streamWriter = new StreamWriter(fs);
           m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
           m_streamWriter.WriteLine(text + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "\n");
           m_streamWriter.Flush();
           m_streamWriter.Close();
       }


I can send two parameter also from properties of window service after installing this but the problem is it is getting started even on passing single parameter.
is there any way that i can prompt user to give two inputs...and any other good way to make window service parameterised??
Posted

1 solution

Quote:
is there any way that i can prompt user to give two inputs

Prompting the user for input when starting a bit against the principles of a Windows Service: running in the background without user-visible windows.

You can do this instead: write another program for configuration. This config program is not a service and shows a window where the user can specify configuration. This configuration can get saved to a file, and your service reads this configuration file when it starts.
 
Share this answer
 
Comments
vicvis 15-Dec-14 7:57am    
U mean to say that i should write a console/window form and create a text/excel/xml file and then let my win service look for input at OnStart() method.Am i right?Appolozies if i am wrong in understanding.
i thought to use onstart(string args[])(something like args[0[] and args[1]).. .any suggestin regarding that and which one should I prefer.??
Thomas Daniels 15-Dec-14 8:04am    
Yes, that's what I mean.

The args array is provided by Windows when it starts the service, not by the user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900