I have generally written services as console apps first, with `Console.WriteLine` injected as a log through the application. Then to create an installer I just look at the command line options, so my main() looks like:

   if (options.Help) {
         // show help
        return;
   }
   if (options.Install) {
        InstallTheService(GetTransactedInstaller());
        return;
   }
   if (options.Uninstall) {
        UninstallTheService(GetTransactedInstaller());
        return;
   }

   // nothing to action, just spin up the service


Then you need to decide whether you are running in console or as a service, and swap out the console for a windows log if required.

If you want to access the service once it is installed I would have a GUI that accesses the service via a socket or RPC or indirectly through the file system or a database, surfaced via something like a notification icon, so WinForms or WPF. There are limitations on services running on the desktop that I believe get stricter the more modern an OS you are running so I wouldn't even bother trying to surface it directly.

But if you want to be able to run a WinForms app that provides a service - think SMTP4DEV, is a notify app that spins up a loopback SMTP server - but with the ability to install that service as a Windows service, you would just replace the command line option solution above with a button in the application that runs the service installer, I'm guessing with options that are controlled in the GUI.

Cheers
Ben Scott
@belfryimages



On 22/07/13 5:34 PM, Tom Rutter wrote:
Does it need to run even when no user is logged in?
If not, then you could just create a gui app as required and add it to the Windows startup list. Much cleaner and using the features already built into Windows.

On Mon, Jul 22, 2013 at 3:43 PM, <[email protected] <mailto:[email protected]>> wrote:

I have gui that provides extra functionality when required but installed as service so a reboot doesn’t affect operation.

    *From:*[email protected]
    <mailto:[email protected]>
    [mailto:[email protected]
    <mailto:[email protected]>] *On Behalf Of *Tom Rutter
    *Sent:* Monday, 22 July 2013 3:26 PM


    *To:* ozDotNet
    *Subject:* Re: Winforms\WIndows Service

    Yeh I maintained an app back in the day that did this for
    debugging purposes. Just had 2 code paths. Don't really need it
    though. I can't think of a reason you would need this off the top
    of my head.

    On Mon, Jul 22, 2013 at 10:13 AM, <[email protected]
    <mailto:[email protected]>> wrote:

    I found some code a while back that allowed me to have an
    application that could run as a service or a  winform
    interface…anyone done this before?

    Anthony



Reply via email to