コード例 #1
0
        static void InstallService(string imageName)
        {
            ShowHeader("Service Installer Invoked");

            if (Utility.IsUserAdministrator() == false)
            {
                Console.WriteLine("\n\nIn order to install the service, you must be a local administrator!\n\n");

                ShowFooter();
                return;
            }

            if (ValisServiceInstaller.IsServiceInstalled(Globals.ServiceName) == false)
            {
                string fileImagePath = AppDomain.CurrentDomain.BaseDirectory + System.AppDomain.CurrentDomain.FriendlyName;
                if (!string.IsNullOrEmpty(imageName))
                {
                    fileImagePath = AppDomain.CurrentDomain.BaseDirectory + imageName;
                }

                Console.WriteLine();
                Console.WriteLine("* Service Name = '{0}'", Globals.ServiceName);
                Console.WriteLine("* Service Path = '{0}'", fileImagePath);

                ValisServiceInstaller.InstallService(Globals.ServiceName, Globals.ServiceName, fileImagePath);
            }
            else
            {
                Console.WriteLine("* The service '{0}' is already installed!", Globals.ServiceName);
            }

            ShowFooter();
        }
コード例 #2
0
        static void RemoveService()
        {
            ShowHeader("Service Remover Invoked");

            if (Utility.IsUserAdministrator() == false)
            {
                Console.WriteLine("\n\nIn order to remove the service, you must be a local administrator!\n\n");

                ShowFooter();
                return;
            }

            if (ValisServiceInstaller.IsServiceInstalled(Globals.ServiceName) == true)
            {
                Console.WriteLine();

                if (ValisServiceInstaller.UninstallService(Globals.ServiceName) == true)
                {
                    Console.WriteLine("* Service '{0}' Removed OK!", Globals.ServiceName);
                }
                else
                {
                    Console.WriteLine("* Service '{0}' did not removed!", Globals.ServiceName);
                }
            }
            else
            {
                Console.WriteLine("* The service '{0}' is not installed!", Globals.ServiceName);
            }
            ShowFooter();
        }