예제 #1
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 { }
        }
예제 #2
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);
            }
        }