示例#1
0
 /// <summary>
 /// Process entry point.
 /// </summary>
 static void Main(string[] args)
 {
     if (Environment.UserInteractive)
     {
         string opt = args.Length > 0 ? args[0] : null;
         if (opt != null)
         {
             if (opt.ToLower() == "/install")
             {
                 WindowsServiceProjectInstaller.Install(args);
                 Environment.Exit(0);
             }
             else if (opt.ToLower() == "/uninstall")
             {
                 WindowsServiceProjectInstaller.Uninstall(args);
                 Environment.Exit(0);
             }
         }
         RunConsole(args, opt);
     }
     else
     {
         Run();
     }
 }
示例#2
0
        public static void Uninstall(string[] args)
        {
            string name = args.Length == 2 ? args[1] : DEFAULT_NAME;

            try {
                TransactedInstaller            ti = new TransactedInstaller();
                WindowsServiceProjectInstaller mi = WindowsServiceProjectInstaller.Create(name);
                ti.Installers.Add(mi);
                string         path    = string.Format("/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location);
                string[]       cmdline = { path };
                InstallContext ctx     = new InstallContext("", cmdline);
                ti.Context = ctx;
                ti.Uninstall(null);
            }
            //Swallow exception when we're trying to uninstall non-existent service
            catch { }
        }
示例#3
0
        public static void Install(string[] args)
        {
            string name = args.Length == 2 ? args[1] : DEFAULT_NAME;

            try {
                TransactedInstaller            ti = new TransactedInstaller();
                WindowsServiceProjectInstaller pi = WindowsServiceProjectInstaller.Create(name);
                ti.Installers.Add(pi);
                string path = string.Format("/assemblypath={0}",
                                            System.Reflection.Assembly.GetExecutingAssembly().Location);
                string[]       cmdline = { path };
                InstallContext ctx     = new InstallContext("", cmdline);
                ti.Context = ctx;
                ti.Install(new Hashtable());
            } catch (Exception ex) {
                Console.WriteLine("ERROR: {0}", ex.Message);
                Environment.Exit(1);
            }
        }