is it possible to have one compiled exe for both app as well as service?

  • Thread starter Thread starter assaf
  • Start date Start date
A

assaf

hi all

i have an application that i would like to be able to run both as a service,
as well as a normal application.
can this be done?

how can i specify to Main(),
that it is one or the other?
how can it tell which mode to run in?


assaf
 
assaf said:
i have an application that i would like to be able to run both as a service,
as well as a normal application.
can this be done?
Yes.

how can i specify to Main(),
that it is one or the other?
how can it tell which mode to run in?

IIRC, you basically need a command line parameter to tell whether or
not to run the ServiceBase.Run method or not.
 
as follows:

static void Main(string[] args) {
....
if (1 == args.Length && args[0].Equals("-console")) {
....
}
else
{
ServiceBase.Run(...);
}
 
Back
Top