当前位置: 首页>>代码示例>>C#>>正文


C# ServiceController.ExecuteCommand方法代码示例

本文整理汇总了C#中System.ServiceProcess.ServiceController.ExecuteCommand方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceController.ExecuteCommand方法的具体用法?C# ServiceController.ExecuteCommand怎么用?C# ServiceController.ExecuteCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ServiceProcess.ServiceController的用法示例。


在下文中一共展示了ServiceController.ExecuteCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveKeyboardList

 /// <summary>
 /// Saves the list of recognized keyboards
 /// </summary>
 /// <param name="dsValidKeyboards"></param>
 /// <param name="path"></param>
 public static void SaveKeyboardList(DataSet dsValidKeyboards, string path)
 {
     try
     {
         string ProfilePathFilename = path + @"\ValidKeyboards.xml";
         ServiceController service = new ServiceController("ActiveAuthenticationService");
         service.ExecuteCommand(143);
         dsValidKeyboards.WriteXml(ProfilePathFilename);
         service.ExecuteCommand(142);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
开发者ID:ActiveAuthentication,项目名称:ActiveAuthentication,代码行数:20,代码来源:KeyboardList.cs

示例2: ReconfigureRCCService

        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);
            }

            return false;
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:32,代码来源:ProTONERemoteConfig.cs

示例3: ReconfigureService

 public static void ReconfigureService()
 {
     try
     {
         ServiceController sc = new ServiceController(ProTONEConstants.RCCServiceShortName);
         sc.ExecuteCommand((int)ServiceCommand.Reconfigure);
     }
     catch
     {
     }
 }
开发者ID:rraguso,项目名称:protone-suite,代码行数:11,代码来源:ServiceControl.cs

示例4: SendSwitchCommand

 private void SendSwitchCommand()
 {
     // Описываем нашу службу
     ServiceController sc = new ServiceController("Sus");
     try
     {
     // посылаем ей команду
     sc.ExecuteCommand(SWITCH_USER_COMMAND);
     }
     catch (Exception ex)
     {
     MessageBox.Show(ex.Message);
     }
 }
开发者ID:jorik041,项目名称:vfsus,代码行数:14,代码来源:SUApplicationContext.cs

示例5: Install

        public override void Install(IDictionary stateSaver)
        {
            Ping p = new Ping();
                try
                {
                    PingReply reply = p.Send("www.google.com", 3000);
                    if (reply.Status != IPStatus.Success)
                    {
                        throw new InstallException("An internet connection is required to install Active Authentication.  Please ensure your computer is connected to the internet and try installing Active Authentication again.");
                    }
                }
                catch
                {
                     throw new InstallException("An internet connection is required to install Active Authentication.  Please ensure your computer is connected to the internet and try installing Active Authentication again.");
                }

            base.Install(stateSaver);
            ServiceController controller;
            ServiceController[] services = ServiceController.GetServices();
            var service = services.FirstOrDefault(s => s.ServiceName == "ActiveAuthenticationService");
            if(service != null)
            {
                controller = new ServiceController("ActiveAuthenticationService");
                if (controller.Status == ServiceControllerStatus.Running)
                    controller.ExecuteCommand(143);
            }
            else
            {
                string path = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)) + @"Windows\Microsoft.NET\Framework\v4.0.30319\" + "installUtil.exe";
                string arg = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System)) + @"Program Files (x86)\Louisiana Tech University\Active Authentication\ActiveAuthenticationService.exe";
                Process srvinst = Process.Start(path, "\"" + arg + "\"");
                srvinst.WaitForExit();
                Process srvsc = Process.Start("cmd", @"/c sc sdset ActiveAuthenticationService D:(A;;LCRPDTLO;;;WD)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)");
                srvsc.WaitForExit();
                controller = new ServiceController("ActiveAuthenticationService");
                if (controller.Status == ServiceControllerStatus.Stopped || controller.Status == ServiceControllerStatus.Paused)
                    controller.Start();
            }
        }
开发者ID:ActiveAuthentication,项目名称:ActiveAuthentication,代码行数:39,代码来源:Installer.cs

示例6: ExecuteCommand_Service_ControlCodes

		public void ExecuteCommand_Service_ControlCodes ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc = new ServiceController ("Schedule", ".");
			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#A");

			try {
				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_CONTINUE);
					Assert.Fail ("#B1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
					Assert.IsNotNull (ex.Message, "#B3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#B4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#B5");
					Assert.IsNotNull (ex.InnerException, "#B6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#B7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#B8");
					Assert.IsNotNull (win32Error.Message, "#B9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#B10");
					Assert.IsNull (win32Error.InnerException, "#B11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_DEVICEEVENT);
					Assert.Fail ("#C1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
					Assert.IsNotNull (ex.Message, "#C3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#C4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#C5");
					Assert.IsNotNull (ex.InnerException, "#C6");

					// The parameter is incorrect
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#C7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#C8");
					Assert.IsNotNull (win32Error.Message, "#C9");
					Assert.AreEqual (87, win32Error.NativeErrorCode, "#C10");
					Assert.IsNull (win32Error.InnerException, "#C11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_HARDWAREPROFILECHANGE);
					Assert.Fail ("#D1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
					Assert.IsNotNull (ex.Message, "#D3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#D4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#D5");
					Assert.IsNotNull (ex.InnerException, "#D6");

					// The parameter is incorrect
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#D7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#D8");
					Assert.IsNotNull (win32Error.Message, "#D9");
					Assert.AreEqual (87, win32Error.NativeErrorCode, "#D10");
					Assert.IsNull (win32Error.InnerException, "#D11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_INTERROGATE);
					Assert.Fail ("#E1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
					Assert.IsNotNull (ex.Message, "#E3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#E4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#E5");
					Assert.IsNotNull (ex.InnerException, "#E6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#E7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#E8");
					Assert.IsNotNull (win32Error.Message, "#E9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#E10");
					Assert.IsNull (win32Error.InnerException, "#E11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_NETBINDADD);
					Assert.Fail ("#F1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
					Assert.IsNotNull (ex.Message, "#F3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#F4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#F5");
					Assert.IsNotNull (ex.InnerException, "#F6");

//.........这里部分代码省略.........
开发者ID:nlhepler,项目名称:mono,代码行数:101,代码来源:ServiceControllerTest.cs

示例7: receiver

        public string receiver(string stuff, string action)
        {
            string path = @"C:\Users\Shahbaaz\efb\in\";
            path += action;
            path += ".txt";
            Away a = new Away();
            a.content = action;
            ServiceController myService = new ServiceController("eFacebookMediatorService");
            myService.ExecuteCommand((int)MyCustomCommands.FileAccess);
            File.WriteAllText(path, stuff);
            int dwStartTime = System.Environment.TickCount;

            a.statusManager = false;
            while (1 != 0)
            {
                if (a.statusManager == true)
                {
                    a.statusManager = false;
                    return a.sendManager;
                }
                else
                    continue;

            }
        }
开发者ID:Baze92,项目名称:WindowsService,代码行数:25,代码来源:Service.cs

示例8: Main

        static void Main(string[] args)
        {
            ServiceController[] scServices;
            scServices = ServiceController.GetServices();

            foreach (ServiceController scTemp in scServices)
            {

                if (scTemp.ServiceName == "Simple Service")
                {
                    // Display properties for the Simple Service sample
                    // from the ServiceBase example.
                    ServiceController sc = new ServiceController("Simple Service");
                    Console.WriteLine("Status = " + sc.Status);
                    Console.WriteLine("Can Pause and Continue = " + sc.CanPauseAndContinue);
                    Console.WriteLine("Can ShutDown = " + sc.CanShutdown);
                    Console.WriteLine("Can Stop = " + sc.CanStop);
                    if (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        sc.Start();
                        while (sc.Status == ServiceControllerStatus.Stopped)
                        {
                            Thread.Sleep(1000);
                            sc.Refresh();
                        }
                    }
                    // Issue custom commands to the service
                    // enum SimpleServiceCustomCommands
                    //    { StopWorker = 128, RestartWorker, CheckWorker };
                    sc.ExecuteCommand((int)SimpleServiceCustomCommands.StopWorker);
                    sc.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker);
                    sc.Pause();
                    while (sc.Status != ServiceControllerStatus.Paused)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    sc.Continue();
                    while (sc.Status == ServiceControllerStatus.Paused)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    sc.Stop();
                    while (sc.Status != ServiceControllerStatus.Stopped)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    String[] argArray = new string[] { "ServiceController arg1", "ServiceController arg2" };
                    sc.Start(argArray);
                    while (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);
                    // Display the event log entries for the custom commands
                    // and the start arguments.
                    EventLog el = new EventLog("Application");
                    EventLogEntryCollection elec = el.Entries;
                    foreach (EventLogEntry ele in elec)
                    {
                        if (ele.Source.IndexOf("SimpleService.OnCustomCommand") >= 0 |
                            ele.Source.IndexOf("SimpleService.Arguments") >= 0)
                            Console.WriteLine(ele.Message);
                    }
                }
            }
            Console.ReadKey();
        }
开发者ID:eandbsoftware,项目名称:MCTS_70_536_AllQuestions,代码行数:74,代码来源:Program.cs

示例9: ExecuteCommand_ServiceName_Empty

		public void ExecuteCommand_ServiceName_Empty ()
		{
			ServiceController sc = new ServiceController ();
			try {
				sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_INTERROGATE);
				Assert.Fail ("#1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
				Assert.IsNotNull (ex.Message, "#3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#5");
				Assert.IsNull (ex.ParamName, "#6");
				Assert.IsNull (ex.InnerException, "#7");
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:ServiceControllerTest.cs

示例10: ExecuteCommand_Service_Stopped

		public void ExecuteCommand_Service_Stopped ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc = new ServiceController ("Schedule", ".");
			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#A");

			sc.Stop ();

			try {
				sc.WaitForStatus (ServiceControllerStatus.Stopped, new TimeSpan (0, 0, 5));
				Assert.AreEqual (ServiceControllerStatus.Stopped, sc.Status, "#B");

				try {
					sc.ExecuteCommand (127);
					Assert.Fail ("#C1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
					Assert.IsNotNull (ex.Message, "#C3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#C4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#C5");
					Assert.IsNotNull (ex.InnerException, "#C6");

					// The parameter is incorrect
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#C7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#C8");
					Assert.IsNotNull (win32Error.Message, "#C9");
					Assert.AreEqual (87, win32Error.NativeErrorCode, "#C10");
					Assert.IsNull (win32Error.InnerException, "#C11");
				}

				try {
					sc.ExecuteCommand (128);
					Assert.Fail ("#D1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
					Assert.IsNotNull (ex.Message, "#D3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#D4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#D5");
					Assert.IsNotNull (ex.InnerException, "#D6");

					// The service has not been started
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#D7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#D8");
					Assert.IsNotNull (win32Error.Message, "#D9");
					Assert.AreEqual (1062, win32Error.NativeErrorCode, "#D10");
					Assert.IsNull (win32Error.InnerException, "#D11");
				}
			} finally {
				EnsureServiceIsRunning (sc);
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#E");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:59,代码来源:ServiceControllerTest.cs

示例11: ControlService

        //서비스로 사용자 명령 전송
        public bool ControlService(int code)
        {
            if (!CelotUtility.IsAdministratorRun())
            {
                Message = "[컨트롤 서비스] 관리자 권한이 필요합니다";
                return false;
            }

            switch (code)
            {
                case ServiceManager.CONTROL_SERVICE_RELOAD_DEVICE:
                    if (QueryServiceStatus() == CelotServiceStatus.Running)
                    {
                        ServiceController sc = new ServiceController(ApplicationConfig.Instance().ServiceName);
                        sc.ExecuteCommand(CONTROL_SERVICE_RELOAD_DEVICE);
                    }
                    break;
            }
            return true;
        }
开发者ID:topayc,项目名称:CelotWireless-Router-Contol-System,代码行数:21,代码来源:ServiceManager.cs

示例12: Reload

        public void Reload()
        {
            const int CronReload = 1;

            try
            {
                var cronMachine = ConfigurationManager.AppSettings["Scheduler.CronService.MachineName"] ?? "localhost";
                var sc = new ServiceController("Scheduler.CronService", cronMachine);
                sc.ExecuteCommand(CronReload);
            }
            catch (Exception ex)
            {
                var message = Helpers.GetFullExceptionMessage("Could not contact cron service.", ex);
                EventLog.WriteEntry(EventLogSource, message, EventLogEntryType.Warning, 2);
            }
        }
开发者ID:d-aguilera,项目名称:Scheduler,代码行数:16,代码来源:Scheduler.cs

示例13: Main

        static void Main(string[] args)
        {
            ServiceController[] scServices = ServiceController.GetServices();
            foreach (ServiceController scTemp in scServices)
            {
                if (scTemp.ServiceName.Equals("TestService"))
                {
                    ServiceController sc = new ServiceController("TestService");
                    Console.WriteLine("Status = " + sc.Status);
                    Console.WriteLine("Can Pause and Continue = " + sc.CanPauseAndContinue);
                    Console.WriteLine("Can Shutdown = " + sc.CanShutdown);
                    Console.WriteLine("Can Stop = " + sc.CanStop);
                    if (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        sc.Start();
                        while (sc.Status == ServiceControllerStatus.Stopped)
                        {
                            Thread.Sleep(1000);
                            sc.Refresh();
                        }
                    }

                    sc.ExecuteCommand((int)SimpleServiceCustomCommands.StopWorker);
                    sc.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker);

                    sc.Stop();
                    while (sc.Status != ServiceControllerStatus.Stopped)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }

                    Console.WriteLine("Status = " + sc.Status);
                    sc.Start();
                    while (sc.Status == ServiceControllerStatus.Stopped)
                    {
                        Thread.Sleep(1000);
                        sc.Refresh();
                    }
                    Console.WriteLine("Status = " + sc.Status);

                    Console.Write(scTemp.ServiceName.PadRight(30));
                    Console.WriteLine(("Status: " + scTemp.Status));

                    EventLog el = new EventLog();
                    el.Source = "MySource";
                    Console.WriteLine("Log: " + el.Log);
                    Console.WriteLine("LogName: " + el.LogDisplayName);

                    EventLogEntryCollection elec = el.Entries;
                    foreach (EventLogEntry ele in elec)
                    {
                        Console.Write(ele.Source + ": ");
                        Console.WriteLine(ele.Message);
                    }

                    ServiceControllerPermission permission = new ServiceControllerPermission();
                    Console.WriteLine("ServiceControllerPermission.Any: " + ServiceControllerPermission.Any);
                    Console.WriteLine("ServicecontrollerPermissions.Local: " + ServiceControllerPermission.Local);
                }
            }
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:62,代码来源:Program.cs

示例14: ApplyChanges

		private void ApplyChanges()
		{
			try
			{
				ActiveQLibrary.Serialization.ConfigGlobal.Config config = new ActiveQLibrary.Serialization.ConfigGlobal.Config();

				config.Threads = Int32.Parse(_tbWorker.Text);
				config.Readers.MailPickUp = Int32.Parse(_tbIntervalMail.Text);
				config.Readers.XmlPickup = Int32.Parse(_tbIntervalTask.Text);
				config.DeleteMailWhenProcessed = this._cbDeleteWhenProcessed.Checked;
				config.LogFiles.MaxSizeEvent = Int32.Parse(this._tbMaxBytesEvent.Text);
				config.LogFiles.MaxSizeError = Int32.Parse(this._tbMaxBytesError.Text);
				config.ActiveMailLicense = _tbActiveMailLicense.Text;

				foreach(string dir in _meMailDir.ListBoxItem.Items)
				{
					config.MailPickupDirectories.Add(dir);
				}

				foreach(ListViewItem lvITem in _meSmtpServer.ListViewItem.Items)
				{
					int index = _meSmtpServer.IndexElement(lvITem.Text,Int32.Parse(lvITem.SubItems[1].Text));
					if (index != -1)
					{
						if (((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Username.Trim() != "" &&
							((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Password.Trim() != "")
								config.SmtpServers.Add(new SmtpServer(((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Host,
																((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Port,
																((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Username,
																Encryption.Encrypt(((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Password)));
						else
							config.SmtpServers.Add(new SmtpServer(((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Host,
								((SmtpServer)_meSmtpServer.ListItemSmtp[index]).Port,
								"",
								""));
					}

				}

				foreach(string xml in _meXmlFile.ListBoxItem.Items)
				{
					config.XmlPickupFiles.Add(xml);
				}

				XmlSerializer serialize = new XmlSerializer( typeof(ActiveQLibrary.Serialization.ConfigGlobal.Config));
				TextWriter writer = new StreamWriter(_configFile);
				serialize.Serialize( writer, config );
				writer.Close();

				try
				{
					ServiceController sc = new ServiceController("ActiveQ");
					sc.ExecuteCommand(230);
				}

				catch
				{
				}
			}

			catch(Exception ex)
			{
				MessageBox.Show(string.Format("Unable write data in '{0}'\n{1}\n{2}",_configFile,ex.Source,ex.Message),"Writing configuration file",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}
开发者ID:haoasqui,项目名称:MailSystem.NET,代码行数:65,代码来源:MainForm.cs

示例15: ExecuteCommand_Service_DoesNotExist

		public void ExecuteCommand_Service_DoesNotExist ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc = new ServiceController ("doesnotexist", ".");
			try {
				sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_INTERROGATE);
				Assert.Fail ("#1");
			} catch (InvalidOperationException ex) {
				// Cannot open doesnotexist service on computer '.'
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
				Assert.IsNotNull (ex.Message, "#3");
				Assert.IsTrue (ex.Message.IndexOf ("doesnotexist") != -1, "#4");
				Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#5");
				Assert.IsNotNull (ex.InnerException, "#6");

				// The filename, directory name, or volume label is incorrect
				Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#7");
				Win32Exception win32Error = (Win32Exception) ex.InnerException;
				//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#8");
				Assert.IsNotNull (win32Error.Message, "#9");
				Assert.AreEqual (1060, win32Error.NativeErrorCode, "#10");
				Assert.IsNull (win32Error.InnerException, "#11");
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:26,代码来源:ServiceControllerTest.cs


注:本文中的System.ServiceProcess.ServiceController.ExecuteCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。