What\'s the best way in C# to set up a utility app that can be run from the command line and produce some output (or write to a file), but that could be run as a Windows service
Yes it can be done.
Your startup class must extend ServiceBase.
You could use your static void Main(string[] args) startup method to parse a command line switch to run in console mode.
Something like:
static void Main(string[] args)
{
if ( args == "blah")
{
MyService();
}
else
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MyService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}