コード例 #1
0
    static void Main(string[] args)
    {
        FileStream fileStream = new FileStream("<PATH_TO_THE_SAME_FILE_AS_SERVICE>", <FileMode.Here>, <FileAccess.Here>);
        // create service controller that will control "MeService" service
        ServiceController Controller = new ServiceController("MeService");

        if (Controller.Status == ServiceControllerStatus.Stopped)
        {
            Controller.Start();
        }
        while (Controller.Status != ServiceControllerStatus.Running)
        {
            ;
        }
        Controller.ExecuteCommand(1);     // redirect the stream.
        string command = string.Empty;

        while ((command = Console.ReadLine()) != "exit")
        {
            if (command == "refresh")
            {
                if (Controller.Status == ServiceControllerStatus.Running)
                {
                    Controller.ExecuteCommand(1337);
                    string performance = fileStream.ReadLine();
                    Console.WriteLine(performance);
                }
            }
        }
    }
コード例 #2
0
ファイル: AgentForm.cs プロジェクト: OmerMachluf/finalproject
        private void btnStartLearning_Click(object sender, System.EventArgs e)
        {
            ServiceController Controller = new ServiceController("EyeDenticaService");

            // Refresh the controller to find out if the service is up
            Controller.Refresh();

            if (Controller.Status == ServiceControllerStatus.Stopped)
            {
                Controller.Start();
            }

            if (Controller.Status == ServiceControllerStatus.Running)
            {
                string str = string.Empty;
                if (this.btnStartLearning.Text.Equals("הפעל למידה"))
                {
                    this.btnStartLearning.Text = "התחל בחינה";
                    Controller.ExecuteCommand((int)OperationType.StartBuilding);
                    str = "indication\nTRUE\n";
                }
                else
                {
                    this.btnStartLearning.Text = "הפעל למידה";
                    Controller.ExecuteCommand((int)OperationType.StartTesting);
                    str =  "indication\nFALSE\n";
                }

                File.WriteAllText(BasePath + "mode.csv", str);
            }
        }
コード例 #3
0
ファイル: program.cs プロジェクト: yashbajra/samples
        static void Main(string[] args)
        {
            ServiceController myService = new ServiceController("SimpleService");

            myService.ExecuteCommand((int)SimpleServiceCustomCommands.StopWorker);
            myService.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker);
            myService.ExecuteCommand((int)SimpleServiceCustomCommands.CheckWorker);
        }
コード例 #4
0
 public void sendStartAction()
 {
     try
     {
         sc.ExecuteCommand((int)PAACommands.ScreenSaverStart);
     }
     catch (InvalidOperationException)
     {
     }
 }
コード例 #5
0
        static void Main(string[] args)
        {
            var service = new ServiceController(5, 5);

            service.CreateNewRover("1", "2", "N");
            service.ExecuteCommand(0, "LMLMLMLMM");

            System.Console.WriteLine(service.GetRover(0).ToString());

            service.CreateNewRover("3", "3", "E");
            service.ExecuteCommand(1, "MMRMMRMRRM");

            System.Console.WriteLine(service.GetRover(1).ToString());
        }
コード例 #6
0
 private void Interval_Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         int          val = int.Parse(Interval.Text);
         StreamWriter sw  = new StreamWriter(path + "config.txt");
         sw.Write(val);
         sw.Close();
         sc.ExecuteCommand(128);
     }
     catch (Exception ex)
     {
         UpdateInfoService(ex.Message);
     }
 }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: rrossenbg/vprint
        private void Run_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(comboBox1.Text))
            {
                return;
            }

            try
            {
                int command = int.Parse(tbCommand.Text);
                ServiceController service = new ServiceController(comboBox1.Text);
                if (service.Status == ServiceControllerStatus.Running)
                {
                    service.ExecuteCommand(command);
                    lblMessage.Text = "Sent";
                }
                else
                {
                    lblMessage.Text = "Not running";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
コード例 #8
0
        private void StartScan(string pathName)
        {
            ServiceController sc = null;

            try
            {
                sc = new ServiceController(ClamConfig.Services.Scan);
            }
            catch (Exception)
            {
                return;
            }

            EnableToolbarButtons(false);
            ScanLogUpdateTimer.Enabled = true;
            LogTabControl.SelectTab("LogScanTabPage");

            // Clear Update Log
            ClearAction();

            // Send our path to scan
            pInfo.AddNotification(ClamConfig.Notification.WHSClamAVScanShare, WHS_Notification_Severity.WHS_INFO, pathName, pathName, "", "", "");
            try
            {
                sc.ExecuteCommand((int)ClamConfig.ServiceCommand.scanShare);
            }
            catch (Exception)
            {
                ThrowError.Throw("Scanning Service is not found on this machine");
                return;
            }
        }
コード例 #9
0
        public static bool ReconfigureRCCService()
        {
            try
            {
                ServiceController sc = new ServiceController(
                    ProTONEConstants.RCCServiceShortName,
                    Environment.MachineName);

                if (sc.Status == ServiceControllerStatus.Running)
                {
                    sc.ExecuteCommand((int)ServiceCommand.Reconfigure);
                }
                else
                {
                    sc.Start();
                    sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10));
                }

                if (sc.Status != ServiceControllerStatus.Running)
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex, false);
            }

            return(false);
        }
コード例 #10
0
        /// <summary>
        /// Executes a command on a named service
        /// </summary>
        /// <param name="name">The name that identifies the service to the system.</param>
        /// <param name="computer">The computer on which the service resides.</param>
        /// <param name="command">The command to execute.</param>
        /// <returns>If the command was executed.</returns>
        public bool ExecuteCommand(string name, string computer = "", int command = 0)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }



            ServiceController service = this.GetService(name, computer);

            if (service.Status != ServiceControllerStatus.Running)
            {
                //Not Running
                _Log.Information(string.Format("The service {0} is not running.", name));
                return(false);
            }
            else
            {
                //Execute Command
                _Log.Information(string.Format("Sending the command to the service {0}.", name));
                service.ExecuteCommand(command);
                return(true);
            }
        }
コード例 #11
0
        private void RunCmd(int cmd)
        {
            ServiceController sc = new ServiceController("LibCECService", Environment.MachineName);

            if (sc.Status != ServiceControllerStatus.Running)
            {
                sc.Start();
                sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(1));
            }

            try
            {
                ServiceControllerPermission scp = new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, Environment.MachineName, "LibCECService");//this will grant permission to access the Service
                scp.Assert();
                sc.Refresh();
                sc.ExecuteCommand(cmd);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message,
                                "LibCEC Service Installer",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
        }
コード例 #12
0
        private void TurnOffKUM()
        {
            var service = new ServiceController("VRArcadeHelperService");

            service.ExecuteCommand((int)Enums.KUMMessageType.DISABLE);
            //service.WaitForStatus(ServiceControllerStatus.Running, timeout);
        }
コード例 #13
0
        private void OrderServiceToRefresh()
        {
            ServiceController service = new ServiceController("USFTRestToCSV");

            if (service.Status == ServiceControllerStatus.Running)
            {
                service.ExecuteCommand(USFTRestToCSV.REFRESH_CONFIG_COMMAND);
            }
            else
            {
                switch (service.Status)
                {
                case ServiceControllerStatus.Stopped:
                    service.Start();
                    service.WaitForStatus(ServiceControllerStatus.Running);
                    OrderServiceToRefresh();
                    break;

                case ServiceControllerStatus.ContinuePending:
                case ServiceControllerStatus.StartPending:
                    service.WaitForStatus(ServiceControllerStatus.Running);
                    OrderServiceToRefresh();
                    break;

                default:
                    return;
                }
            }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: rtbhosale/SmartTouch
 void Alert(ServiceController service)
 {
     try
     {
         HostLogger.Get <ServiceStatusChecker>().Info(service.DisplayName + " is : " + service.Status.ToString());
         if (service.Status == ServiceControllerStatus.Stopped)
         {
             SendMail(service);
             Thread.Sleep(1000);
             service.Refresh();
             try
             {
                 HostLogger.Get <ServiceStatusChecker>().Info("Restarting Service : " + service.DisplayName);
                 service.ExecuteCommand((int)SimpleServiceCommands.RestartWorker);
             }
             catch (Exception e)
             {
                 HostLogger.Get <ServiceStatusChecker>().Error("Failed to restart service : ", e);
             }
         }
     }
     catch (Exception e)
     {
         HostLogger.Get <ServiceStatusChecker>().Error("Service doesn't exist ", e);
     }
 }
コード例 #15
0
ファイル: ServiceBaseTests.cs プロジェクト: z77ma/runtime
        public void TestOnExecuteCustomCommand()
        {
            if (PlatformDetection.IsWindowsServerCore)
            {
                throw new SkipTestException("Skip on Windows Server Core"); // https://github.com/dotnet/runtime/issues/43207
            }

            ServiceController controller = ConnectToServer();

            controller.ExecuteCommand(128);
            // Response from test service:
            //  128 => Environment.UserInteractive == false
            //  129 => Environment.UserInteractive == true
            //
            // On Windows Nano and other SKU that do not expose Window Stations, Environment.UserInteractive
            // will always return true, even within a service process.
            // Otherwise, we expect it to be false.
            // (This is the only place we verify Environment.UserInteractive can return false)
            byte expected = PlatformDetection.HasWindowsShell ? (byte)128 : (byte)129;

            Assert.Equal(expected, _testService.GetByte());

            controller.Stop();
            Assert.Equal((int)PipeMessageByteCode.Stop, _testService.GetByte());
            controller.WaitForStatus(ServiceControllerStatus.Stopped);
        }
コード例 #16
0
ファイル: Configuration.cs プロジェクト: radtek/Bummer
 internal static void ReloadService()
 {
     try {
         ServiceController service = new ServiceController("BummerService");
         service.ExecuteCommand(ReLoadSchedulesCommand);
         //service.Status == ServiceControllerStatus.Running
     } catch {}
 }
コード例 #17
0
ファイル: frmMain.cs プロジェクト: Thanak1234/test
 private void btnPull_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Would you like to pull new email?", "Confirm!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
     {
         return;
     }
     service.ExecuteCommand(128);
 }
コード例 #18
0
        public static async Task <bool> CommandService(
            [NotNull] string serviceName,
            int command,
            CancellationToken token = default(CancellationToken))
        {
            if (serviceName == null)
            {
                throw new ArgumentNullException("serviceName");
            }

            try
            {
                new ServiceControllerPermission(
                    ServiceControllerPermissionAccess.Control,
                    Environment.MachineName,
                    serviceName).Assert();
                using (ServiceController controller = new ServiceController(serviceName, Environment.MachineName))
                    switch (controller.Status)
                    {
                    case ServiceControllerStatus.Running:
                        // ReSharper disable once AccessToDisposedClosure, PossibleNullReferenceException
                        await Task.Run(() => controller.ExecuteCommand(command), token).ConfigureAwait(false);

                        return(!token.IsCancellationRequested);

                    case ServiceControllerStatus.ContinuePending:
                    case ServiceControllerStatus.StartPending:
                        if (!await WaitForAsync(controller, ServiceControllerStatus.Running, token)
                            .ConfigureAwait(false))
                        {
                            return(false);
                        }
                        // ReSharper disable once AccessToDisposedClosure, PossibleNullReferenceException
                        await Task.Run(() => controller.ExecuteCommand(command), token).ConfigureAwait(false);

                        return(!token.IsCancellationRequested);

                    default:
                        return(false);
                    }
            }
            catch (TaskCanceledException)
            {
                return(false);
            }
        }
コード例 #19
0
        private void TurnOnKUM()
        {
            var service = new ServiceController("VRArcadeHelperService");

            bool isReEnforceKUM = false;

            bool.TryParse(Utility.GetSystemConfig(Enums.SysConfigType.RE_DISABLE_KMU_AFTER_20_MIN), out isReEnforceKUM);

            if (isReEnforceKUM)
            {
                service.ExecuteCommand((int)Enums.KUMMessageType.ENABLE_ONLY_20_MIN);
            }
            else
            {
                service.ExecuteCommand((int)Enums.KUMMessageType.ENABLE);
            }

            //service.WaitForStatus(ServiceControllerStatus.Running, timeout);
        }
コード例 #20
0
        static void Main(string[] args)
        {
            ServiceController sc = new ServiceController(args[0], Environment.MachineName);

            for (var index = 1; index < args.Length; index++)
            {
                var s = args[index];
                sc.ExecuteCommand(Convert.ToInt32(s));
            }
        }
コード例 #21
0
ファイル: FormMain.cs プロジェクト: vzabrodin/netshare
 private void btnStart_Click(object sender, EventArgs e)
 {
     _service.Refresh();
     if (_service.Status != ServiceControllerStatus.Running)
     {
         if (MessageBox.Show("NetShare Service is stopped. Do you want to restart service?", "NetShare", MessageBoxButtons.YesNo) != DialogResult.Yes)
         {
             return;
         }
         Application.Restart();
     }
     if (!ConfigValidate())
     {
         return;
     }
     ConfigSave();
     _service.ExecuteCommand(200);
     lblIsStarted.Text = "Waiting...";
 }
コード例 #22
0
 public static void ReconfigureService()
 {
     try
     {
         ServiceController sc = new ServiceController(ProTONEConstants.RCCServiceShortName);
         sc.ExecuteCommand((int)ServiceCommand.Reconfigure);
     }
     catch
     {
     }
 }
コード例 #23
0
        public void TestOnExecuteCustomCommand()
        {
            ServiceController controller = ConnectToServer();

            controller.ExecuteCommand(128);
            Assert.Equal(128, _testService.GetByte());

            controller.Stop();
            Assert.Equal((int)PipeMessageByteCode.Stop, _testService.GetByte());
            controller.WaitForStatus(ServiceControllerStatus.Stopped);
        }
コード例 #24
0
ファイル: MainForm.cs プロジェクト: sakpung/webstudy
 private void ForceServiceReload()
 {
     //Force the service to reload the settings
     using (ServiceController conversionService = new ServiceController(Constants.ServiceName))
     {
         if (conversionService.Status == ServiceControllerStatus.Running)
         {
             conversionService.ExecuteCommand(Constants.ReloadSettingsCommand);
         }
     }
 }
コード例 #25
0
        private void executeRequest(string request)
        {
            List <string> listOfRequests = new List <string>();

            listOfRequests.Add(request);
            File.AppendAllLines(Parameters.bufferAddress.PathForRequestBuff, listOfRequests);

            ServiceController sc = new ServiceController("DDDDemoServerService");

            sc.ExecuteCommand(200);
        }
コード例 #26
0
ファイル: MainForm.cs プロジェクト: zvit-cc/MailSystem.NET
 protected override void WndProc(ref Message message)
 {
     if (message.Msg == (int)WM.WM_QUERYENDSESSION)
     {
         ServiceController sc = new ServiceController("ActiveQ");
         sc.ExecuteCommand(221);
     }
     else
     {
         base.WndProc(ref message);
     }
 }
コード例 #27
0
 /// <summary>
 /// RequestReaudit
 /// ==============
 ///
 /// Request a re-audit of the specified computer
 ///
 /// </summary>
 public int RequestReaudit()
 {
     try
     {
         ServiceController agentController = new ServiceController(AuditWizardAgentServiceName, ComputerName);
         agentController.ExecuteCommand(AGENT_REQUEST_REAUDIT);
         return(0);
     }
     catch (Exception)
     {
         return(-1);
     }
 }
コード例 #28
0
        private void VRArcadeHelper()
        {
            bool isDisableByDefault = false;

            bool.TryParse(Utility.GetSystemConfig(Enums.SysConfigType.DISABLE_KMU_BY_DEFAULT), out isDisableByDefault);

            if (isDisableByDefault && !_isDisableKUMExecuted)
            {
                var service = new ServiceController("VRArcadeHelperService");
                service.ExecuteCommand((int)Enums.KUMMessageType.DISABLE);
                _isDisableKUMExecuted = true;
            }
        }
コード例 #29
0
        private static void QuickCheck()
        {
            try
            {
                ServiceController serviceController = new ServiceController(WebSettings.GetServiceName(),
                                                                            WebSettings.GetServiceLocation());

                serviceController.ExecuteCommand((int)ServiceCustomCommand.StartCheck);
            }
            catch (Exception ex)
            {
                new ExceptionLogger().HandleException(ex);
            }
        }
コード例 #30
0
 private static void serviceAgentExecuteCommand(int number, bool silent)
 {
     try
     {
         using (var agentService = new ServiceController(Services.AgentService))
         {
             if (agentService.Status == ServiceControllerStatus.Running)
             {
                 agentService.ExecuteCommand(number);
             }
         }
     }
     catch (Exception) { return; }
 }