-
-
Save gtechsltn/9621485101ccdc42881fee9ec1204cb4 to your computer and use it in GitHub Desktop.
self install windows service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.ServiceProcess; | |
using System.Text; | |
using System.Reflection; | |
using System.Configuration.Install; | |
namespace test | |
{ | |
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (Environment.UserInteractive) | |
{ | |
// If placed in a shared DLL, change to .GetCallingAssembly() | |
var assembly = Assembly.GetExecutingAssembly(); | |
string parameter = args.Length > 0 ? args[0] : ""; | |
switch (parameter) | |
{ | |
case "--install": | |
case "-i": | |
case "/i": | |
ManagedInstallerClass.InstallHelper(new string[] { assembly.Location }); | |
break; | |
case "--uninstall": | |
case "-u": | |
case "/u": | |
ManagedInstallerClass.InstallHelper(new string[] { "/u", assembly.Location }); | |
break; | |
default: | |
using (var service = new TestService()) | |
{ | |
service.StartDebug(); | |
Console.WriteLine("Press [ENTER] ..."); | |
Console.ReadLine(); | |
} | |
break; | |
} | |
} | |
else | |
{ | |
ServiceBase.Run(new TestService()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment