Ejemplo n.º 1
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            string svcPath;

            string svcName;
            string svcDispName;

            ServiceInstaller c = new ServiceInstaller();

            if (args.Length == 3 || args.Length == 2)
            {
                svcPath     = args[2];
                svcName     = args[1];
                svcDispName = args[1];

                if (String.Equals(args[0], "-install", StringComparison.CurrentCultureIgnoreCase))
                {
                    c.InstallService(svcPath, svcName, svcDispName);
                    Console.WriteLine("Attempted to install " + svcName);
                }
                else if (String.Equals(args[0], "-uninstall", StringComparison.CurrentCultureIgnoreCase))
                {
                    c.UnInstallService(svcName);
                    Console.WriteLine("Attempted to uninstall " + svcName);
                }
                else
                {
                    Console.WriteLine("Use command line arguments -Install or -Uninstall, <ServiceName>, <Path>\n" +
                                      "Example: SvcInstaller.exe -Install ServiceDisplayName \"C:\\ServicePath\\Service.exe\"\n" +
                                      "         SvcInstaller.exe - Uninstall ServiceDisplayName");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("Use command line arguments -Install or -Uninstall, <Path>, <DisplayName>\n" +
                                  "Example: SvcInstaller.exe -Install \"C:\\ServicePath\\Service.exe\" ServiceDisplayName");
                Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            // TODO: Add code to start application here


            #region Testing
            //  Testing --------------
            string svcPath;
            string svcName;
            string svcDispName;

            //path to the service that you want to install
            svcPath     = @"C:\build\service\Debug\Service.exe";
            svcDispName = "Service Display Name";
            svcName     = "Service Name";

            ServiceInstaller c = new ServiceInstaller();
            c.InstallService(svcPath, svcName, svcDispName);

            Console.Read();
            Testing--------------
            #endregion Testing
        }