コード例 #1
0
        public static void Uninstall()
        {
            TransactedInstaller ti = new TransactedInstaller();
            SvcInstaller        mi = new SvcInstaller();

            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);
        }
コード例 #2
0
        public static void Install(string args)
        {
            TransactedInstaller ti = new TransactedInstaller();
            SvcInstaller        mi = new SvcInstaller();

            ti.Installers.Add(mi);
            String path = String.Format("/assemblypath={0}", Assembly.GetExecutingAssembly().Location);

            String[] cmdline = { path };
            Console.WriteLine("Installing at path " + path + " with args " + args);
            InstallContext ctx = new InstallContext("", cmdline);

            //ctx.Parameters["assemblypath"] += "\" " + args;
            ti.Context = ctx;
            ti.Install(new System.Collections.Hashtable());
        }
コード例 #3
0
        static int Main(string[] args)
        {
            _Args = args;
            if (System.Environment.UserInteractive || (args != null && args.Length > 0))
            {
                if (args != null && args.Length > 0)
                {
                    string   parameter = "";
                    string[] paramArgs = null;
                    if (args.Length > 1)
                    {
                        paramArgs = new string[args.Length - 1];
                        Array.Copy(args, 1, paramArgs, 0, paramArgs.Length);
                        parameter = String.Join(" ", paramArgs);
                    }
                    switch (args[0])
                    {
                    case "--installSvc":
                        if (IsInstalled())
                        {
                            Console.WriteLine("Service already installed");
                            break;
                        }
                        if (!IsUserAdministrator())
                        {
                            Console.WriteLine("\r\n ** Must be run as Adminstrator to install ** ");
                            break;
                        }
                        Console.WriteLine("Starting installation...");
                        SvcInstaller.Install(parameter);
                        Console.WriteLine("Press any key to quit...");
                        Console.ReadKey();
                        //ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                        break;

                    case "--uninstallSvc":
                        if (!IsUserAdministrator())
                        {
                            Console.WriteLine("\r\n ** Must be run as Adminstrator to un-install ** ");
                            return(0);
                        }
                        SvcInstaller.Uninstall();
                        //ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
                        break;

                    case "--console":
                        LoadAndRunServiceObject(_Args);
                        Console.WriteLine("Press any key to stop service...");
                        Console.ReadKey();
                        Program.StopService();
                        Console.WriteLine("Press any key to quit...");
                        Console.ReadKey();
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Usage:");
                    Console.WriteLine("--installSvc | --uninstallSvc | --console ");
                    Console.WriteLine("Press any key to exit...");
                    Console.ReadKey();
                    return(0);
                }
            }
            else
            {
                ServiceBase.Run(new Program());
                return(0);
            }
            return(0);
        }