Ejemplo n.º 1
0
        private void BtnStartService_Click(object sender, EventArgs e)
        {
            var isSuccess = ServiceInstaller.SystemServiceOpen(ServiceName);

            if (isSuccess)
            {
                btnStartService.Enabled = false;
                btnStopService.Enabled  = true;
                btnRestart.Enabled      = true;
                Console.WriteLine($"{ServiceName} start success");
            }
        }
Ejemplo n.º 2
0
        private void BtnInstall_Click(object sender, EventArgs e)
        {
            string filePath  = Assembly.GetExecutingAssembly().Location;
            var    isSuccess = ServiceInstaller.InstallService(filePath);

            if (isSuccess)
            {
                btnInstall.Enabled   = false;
                btnUninstall.Enabled = true;
                Console.WriteLine($"Install {ServiceName} success");
                isSuccess = ServiceInstaller.SystemServiceOpen(ServiceName);
                Console.WriteLine("service start" + (isSuccess ? "success" : "failed"));
                if (isSuccess)
                {
                    btnRestart.Enabled     = true;
                    btnStopService.Enabled = true;
                }
            }
            else
            {
                Console.WriteLine($"install {ServiceName} failed");
            }
        }