/// <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);
     }
 }
        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;
        }
 public static void ReconfigureService()
 {
     try
     {
         ServiceController sc = new ServiceController(ProTONEConstants.RCCServiceShortName);
         sc.ExecuteCommand((int)ServiceCommand.Reconfigure);
     }
     catch
     {
     }
 }
Beispiel #4
0
 private void SendSwitchCommand()
 {
     // Описываем нашу службу
     ServiceController sc = new ServiceController("Sus");
     try
     {
     // посылаем ей команду
     sc.ExecuteCommand(SWITCH_USER_COMMAND);
     }
     catch (Exception ex)
     {
     MessageBox.Show(ex.Message);
     }
 }
Beispiel #5
0
 public static bool SendServiceCmd(string svcName, int command)
 {
     try
     {
         var service = new System.ServiceProcess.ServiceController(svcName);
         service.ExecuteCommand(command);
         return(true);
     }
     catch (Exception ex)
     {
         Log("* could not access the service controller: " + ex.ToString());
         return(false);
     }
 }
        private static void serviceExecuteCommand(int number, bool silent)
        {
            ServiceController mainService;

            if (isInTerminalServerSession())
            {
                return;
            }
            if (!isHicapsConnectServiceInstalled())
            {
                return;
            }
            try
            {
                mainService = new System.ServiceProcess.ServiceController(Services.MainService);
            }
            catch (Exception)
            {
                return;
            }
            try
            {
                mainService.Refresh();

                if (mainService.Status != System.ServiceProcess.ServiceControllerStatus.Running)
                {
                    // if (IsAnAdministrator())
                    //{
                    StopStartService(true);
                    // }
                }

                if (mainService.Status == System.ServiceProcess.ServiceControllerStatus.Running)
                {
                    mainService.ExecuteCommand(number);
                    //waitConfigurationScreen();
                }
                else
                {
                    //ShowServiceNotRunningBox(silent);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        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();
            }
        }
Beispiel #8
0
		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");
			}
		}
Beispiel #9
0
		public void ExecuteCommand_Service_StopPending ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

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

			sc.Stop ();

			try {
				try {
					sc.ExecuteCommand (127);
					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");

					// The parameter is incorrect
					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 (87, win32Error.NativeErrorCode, "#B10");
					Assert.IsNull (win32Error.InnerException, "#B11");
				}

				try {
					sc.ExecuteCommand (128);
					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 service cannot accept control messages at this time
					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 (1061, win32Error.NativeErrorCode, "#C10");
					Assert.IsNull (win32Error.InnerException, "#C11");
				}
			} finally {
				EnsureServiceIsRunning (sc);
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#D");
		}
Beispiel #10
0
		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");
		}
Beispiel #11
0
		public void ExecuteCommand_Service_Paused ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

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

			sc.Pause ();

			try {
				sc.WaitForStatus (ServiceControllerStatus.Paused, new TimeSpan (0, 0, 5));
				Assert.AreEqual (ServiceControllerStatus.Paused, sc.Status, "#B");
				sc.ExecuteCommand (154);
				sc.Refresh ();
				Assert.AreEqual (ServiceControllerStatus.Paused, sc.Status, "#C");
				//sc.ExecuteCommand (127);
			} finally {
				EnsureServiceIsRunning (sc);
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#D");
		}
Beispiel #12
0
		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");
			}
		}
Beispiel #13
0
        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);
            }
        }
Beispiel #14
0
		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);
			}
		}
Beispiel #15
0
        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);
                }
            }
        }
Beispiel #16
0
		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);
			
		}
 public void SendServiceCommand(string serviceName, int command)
 {
     using (var sc = new ServiceController(serviceName))
     {
         if (sc.Status == ServiceControllerStatus.Running)
         {
             sc.ExecuteCommand(command);
         }
         else
         {
             _log.WarnFormat("The {0} service can't be commanded now as it has the status {1}. Try again later...",
                 serviceName, sc.Status.ToString());
         }
     }
 }
Beispiel #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;
            }
        }
		public void ExecuteCommand_Service_PausePending ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

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

			sc.Pause ();

			try {
				sc.ExecuteCommand (128);

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

					// The parameter is incorrect
					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 (87, win32Error.NativeErrorCode, "#B10");
					Assert.IsNull (win32Error.InnerException, "#B11");
				}
			} finally {
				EnsureServiceIsRunning (sc);
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#C");
		}
Beispiel #20
0
        /// <summary>
        /// 重启服务
        /// </summary>
        void resetService()
        {
            CommiServer.GlobalServer.Stop();
            this.srvTrans.Close();
            CommiManager.GlobalManager.ClearCommand();
            ThreadManager.AbortAll();
            CommiManager.GlobalManager.ResetClient();
            DeviceEatery.ResetQueue();
            DeviceDoor.ResetQueue();
            DeviceChannel.ResetQueue();
            channelmgr.ResetRecord();
            monimgr.Resetdev();

            Monitor.Enter(argsExtendList);
            argsExtendList.Clear();
            Monitor.PulseAll(argsExtendList);
            Monitor.Exit(argsExtendList);
            isRunExtend = false;
            isResetService = false;

            ServiceController ctrl = new ServiceController("Granity服务守护");
            LogMessage("自动重启Granity文件服务", null, EventLogEntryType.Information);
            ctrl.ExecuteCommand(200);
            return;

            CommiServer commisrv = CommiServer.GlobalServer;
            commisrv.Stop();
            this.srvTrans.Close();
            if (ThreadManager.IsResetNeed || isResetService)
            {
                CommiManager.GlobalManager.ClearCommand();
                ThreadManager.AbortAll();
                CommiManager.GlobalManager.ResetClient();
                DeviceEatery.ResetQueue();
                DeviceDoor.ResetQueue();
                DeviceChannel.ResetQueue();
                channelmgr.ResetRecord();
                monimgr.Resetdev();

                Monitor.Enter(argsExtendList);
                argsExtendList.Clear();
                Monitor.PulseAll(argsExtendList);
                Monitor.Exit(argsExtendList);
                isRunExtend = false;
                isResetService = false;
            }
            Thread.Sleep(new TimeSpan(0, 1, 0));

            SvrFileTrans svrfile = new SvrFileTrans();
            svrfile.ExtendHandle += new EventHandler<ExtendEventArgs>(svrfile_ExtendHandle);
            commisrv.Start(this.port, svrfile);
            this.srvTrans = svrfile;
            NameValueCollection data = new NameValueCollection();
            data["服务"] = this.ServiceName;
            data["端口"] = this.port.ToString();
            LogMessage("自动重启Granity文件服务", data, EventLogEntryType.Information);
        }
        //서비스로 사용자 명령 전송
        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;
        }
Beispiel #22
0
		public void Constructor1 ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc = new ServiceController ();

			try {
				bool value = sc.CanPauseAndContinue;
				Assert.Fail ("#A1: " + value.ToString ());
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
				Assert.IsNotNull (ex.Message, "#A3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#A4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#A5");
				Assert.IsNull (ex.ParamName, "#A6");
				Assert.IsNull (ex.InnerException, "#A7");
			}

			try {
				bool value = sc.CanShutdown;
				Assert.Fail ("#B1: " + value.ToString ());
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
				Assert.IsNotNull (ex.Message, "#B3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#B4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#B5");
				Assert.IsNull (ex.ParamName, "#B6");
				Assert.IsNull (ex.InnerException, "#B7");
			}

			try {
				bool value = sc.CanStop;
				Assert.Fail ("#C1: " + value.ToString ());
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#C2");
				Assert.IsNotNull (ex.Message, "#C3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#C4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#C5");
				Assert.IsNull (ex.ParamName, "#C6");
				Assert.IsNull (ex.InnerException, "#C7");
			}

			// closing the ServiceController does not result in exception
			sc.Close ();

			try {
				sc.Continue ();
				Assert.Fail ("#D1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#D2");
				Assert.IsNotNull (ex.Message, "#D3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#D4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#D5");
				Assert.IsNull (ex.ParamName, "#D6");
				Assert.IsNull (ex.InnerException, "#D7");
			}

			try {
				Assert.Fail ("#E1: " + sc.DependentServices.Length);
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#E2");
				Assert.IsNotNull (ex.Message, "#E3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#E4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#E5");
				Assert.IsNull (ex.ParamName, "#E6");
				Assert.IsNull (ex.InnerException, "#E7");
			}

			Assert.IsNotNull (sc.DisplayName, "#F1");
			Assert.AreEqual (string.Empty, sc.DisplayName, "#F2");

			try {
				sc.ExecuteCommand (0);
				Assert.Fail ("#G1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#G2");
				Assert.IsNotNull (ex.Message, "#G3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#G4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#G5");
				Assert.IsNull (ex.ParamName, "#G6");
				Assert.IsNull (ex.InnerException, "#G7");
			}

			Assert.IsNotNull (sc.MachineName, "#H1");
			Assert.AreEqual (".", sc.MachineName, "#H2");


			try {
				sc.Pause ();
				Assert.Fail ("#I1");
			} catch (ArgumentException ex) {
				// Service name  contains invalid characters, is empty or is
				// too long (max length = 80)
				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#I2");
				Assert.IsNotNull (ex.Message, "#I3");
				Assert.IsTrue (ex.Message.IndexOf ("  ") != -1, "#I4");
				Assert.IsTrue (ex.Message.IndexOf ("80") != -1, "#I5");
				Assert.IsNull (ex.ParamName, "#I6");
				Assert.IsNull (ex.InnerException, "#I7");
			}
		}
        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();
        }
Beispiel #24
0
		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");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#F7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#F8");
					Assert.IsNotNull (win32Error.Message, "#F9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#F10");
					Assert.IsNull (win32Error.InnerException, "#F11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_NETBINDDISABLE);
					Assert.Fail ("#G1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
					Assert.IsNotNull (ex.Message, "#G3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#G4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#G5");
					Assert.IsNotNull (ex.InnerException, "#G6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#G7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#G8");
					Assert.IsNotNull (win32Error.Message, "#G9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#G10");
					Assert.IsNull (win32Error.InnerException, "#G11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_NETBINDENABLE);
					Assert.Fail ("#H1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#H2");
					Assert.IsNotNull (ex.Message, "#H3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#H4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#H5");
					Assert.IsNotNull (ex.InnerException, "#H6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#H7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#H8");
					Assert.IsNotNull (win32Error.Message, "#H9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#H10");
					Assert.IsNull (win32Error.InnerException, "#H11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_NETBINDREMOVE);
					Assert.Fail ("#I1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#I2");
					Assert.IsNotNull (ex.Message, "#I3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#I4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#I5");
					Assert.IsNotNull (ex.InnerException, "#I6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#I7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#I8");
					Assert.IsNotNull (win32Error.Message, "#I9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#I10");
					Assert.IsNull (win32Error.InnerException, "#I11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_PARAMCHANGE);
					Assert.Fail ("#J1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#J2");
					Assert.IsNotNull (ex.Message, "#J3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#J4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#J5");
					Assert.IsNotNull (ex.InnerException, "#J6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#J7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#J8");
					Assert.IsNotNull (win32Error.Message, "#J9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#J10");
					Assert.IsNull (win32Error.InnerException, "#J11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_PAUSE);
					Assert.Fail ("#K1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#K2");
					Assert.IsNotNull (ex.Message, "#K3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#K4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#K5");
					Assert.IsNotNull (ex.InnerException, "#K6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#K7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#K8");
					Assert.IsNotNull (win32Error.Message, "#K9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#K10");
					Assert.IsNull (win32Error.InnerException, "#K11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_POWEREVENT);
					Assert.Fail ("#L1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#L2");
					Assert.IsNotNull (ex.Message, "#L3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#L4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#L5");
					Assert.IsNotNull (ex.InnerException, "#L6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#L7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#L8");
					Assert.IsNotNull (win32Error.Message, "#L9");
					Assert.AreEqual (87, win32Error.NativeErrorCode, "#L10");
					Assert.IsNull (win32Error.InnerException, "#L11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_SESSIONCHANGE);
					Assert.Fail ("#M1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#M2");
					Assert.IsNotNull (ex.Message, "#M3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#M4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#M5");
					Assert.IsNotNull (ex.InnerException, "#M6");

					// The parameter is incorrect
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#M7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#M8");
					Assert.IsNotNull (win32Error.Message, "#M9");
					Assert.AreEqual (87, win32Error.NativeErrorCode, "#M10");
					Assert.IsNull (win32Error.InnerException, "#M11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_SHUTDOWN);
					Assert.Fail ("#N1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#N2");
					Assert.IsNotNull (ex.Message, "#N3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#N4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#N5");
					Assert.IsNotNull (ex.InnerException, "#N6");

					// The parameter is incorrect
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#N7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#N8");
					Assert.IsNotNull (win32Error.Message, "#N9");
					Assert.AreEqual (87, win32Error.NativeErrorCode, "#N10");
					Assert.IsNull (win32Error.InnerException, "#N11");
				}

				try {
					sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_STOP);
					Assert.Fail ("#O1");
				} catch (InvalidOperationException ex) {
					// Cannot control Schedule service on computer '.'
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#O2");
					Assert.IsNotNull (ex.Message, "#O3");
					Assert.IsTrue (ex.Message.IndexOf ("Schedule") != -1, "#O4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#O5");
					Assert.IsNotNull (ex.InnerException, "#O6");

					// Access is denied
					Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#O7");
					Win32Exception win32Error = (Win32Exception) ex.InnerException;
					//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#O8");
					Assert.IsNotNull (win32Error.Message, "#O9");
					Assert.AreEqual (5, win32Error.NativeErrorCode, "#O10");
					Assert.IsNull (win32Error.InnerException, "#O11");
				}
			} finally {
				EnsureServiceIsRunning (sc);
			}

			Assert.AreEqual (ServiceControllerStatus.Running, sc.Status, "#P");
		}
Beispiel #25
0
        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;

            }
        }
        public static void ExecuteCommand(string serviceName, ServiceCommandEnum serviceCommand)
        {
            System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController(serviceName);

            switch (serviceCommand)
            {
            case ServiceCommandEnum.Start:
                try
                {
                    Logging.Log(LogLevelEnum.Info, "Starting service");
                    serviceController.Start();
                    serviceController.WaitForStatus(ServiceControllerStatus.Running);
                    Logging.Log(LogLevelEnum.Info, "Service started");
                }
                catch (Exception ex)
                {
                    Logging.Log(LogLevelEnum.Fatal, "Start failed: " + FileLogger.GetInnerException(ex).Message);
                    MessageBox.Show("Could not start " + Settings.Instance.ServiceDisplayName);
                }
                break;

            case ServiceCommandEnum.Stop:
                try
                {
                    Logging.Log(LogLevelEnum.Info, "Stopping service");
                    serviceController.Stop();
                    serviceController.WaitForStatus(ServiceControllerStatus.Stopped);
                    Logging.Log(LogLevelEnum.Info, "Service stopped");
                }
                catch (Exception ex)
                {
                    Logging.Log(LogLevelEnum.Fatal, "Stop failed: " + FileLogger.GetInnerException(ex).Message);
                    MessageBox.Show("Could not stop " + Settings.Instance.ServiceName);
                }
                break;

            case ServiceCommandEnum.Restart:
                try
                {
                    Logging.Log(LogLevelEnum.Info, "Restarting service");
                    serviceController.Stop();
                    serviceController.WaitForStatus(ServiceControllerStatus.Stopped);
                    serviceController.Start();
                    serviceController.WaitForStatus(ServiceControllerStatus.Running);
                    Logging.Log(LogLevelEnum.Info, "Service restarted");
                }
                catch (Exception ex)
                {
                    Logging.Log(LogLevelEnum.Fatal, "Restart failed: " + FileLogger.GetInnerException(ex).Message);
                    MessageBox.Show("Could not restart " + Settings.Instance.ServiceName);
                }
                break;

            case ServiceCommandEnum.Uninstall:
                try
                {
                    Logging.Log(LogLevelEnum.Info, "Uninstalling service");

                    if (ServiceControl.ServiceStatus != ServiceControllerStatus.Running)
                    {
                        serviceController.Start();
                        serviceController.WaitForStatus(ServiceControllerStatus.Running);
                    }

                    serviceController.ExecuteCommand((int)ServiceCommandEnum.Uninstall);
                    serviceController.Close();

                    Thread.Sleep(250);
                    File.Delete(Settings.Instance.ServiceFile);

                    Logging.Log(LogLevelEnum.Info, "Service uninstalled");
                    return;
                }
                catch (Exception ex)
                {
                    Logging.Log(LogLevelEnum.Fatal, "Uninstall failed: " + FileLogger.GetInnerException(ex).Message);
                    MessageBox.Show("Could not uninstall " + Settings.Instance.ServiceName);
                }
                break;
            }

            serviceController.Close();
        }
Beispiel #27
0
        public static void Index()
        {
            if (!IsInstalled()) return;

            using (ServiceController controller = new ServiceController("TreeGUISvc"))
            {
                try
                {
                    controller.Refresh();
                    if (controller.Status != ServiceControllerStatus.Running)
                    {
                        controller.Start();
                    }
                    controller.ExecuteCommand((int)ServiceCommand.Index);
                }
                catch
                {
                    throw;
                }
            }
        }
Beispiel #28
0
		public void ExecuteCommand_Machine_DoesNotExist ()
		{
			if (RunningOnUnix)
				Assert.Ignore ("Running on Unix.");

			ServiceController sc = new ServiceController ("Schedule",
				"doesnotexist");
			try {
				sc.ExecuteCommand ((int) SERVICE_CONTROL_TYPE.SERVICE_CONTROL_PAUSE);
				Assert.Fail ("#1");
			} catch (InvalidOperationException ex) {
				// Cannot open Service Control Manager on computer 'doesnotexist'.
				// This operation might require other priviliges
				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
				Assert.IsNotNull (ex.Message, "#3");
				Assert.IsTrue (ex.Message.IndexOf ("'doesnotexist'") != -1, "#4");
				Assert.IsNotNull (ex.InnerException, "#5");

				// The RPC server is unavailable
				Assert.AreEqual (typeof (Win32Exception), ex.InnerException.GetType (), "#6");
				Win32Exception win32Error = (Win32Exception) ex.InnerException;
				//Assert.AreEqual (-2147467259, win32Error.ErrorCode, "#7");
				Assert.IsNotNull (win32Error.Message, "#8");
				Assert.AreEqual (1722, win32Error.NativeErrorCode, "#9");
				Assert.IsNull (win32Error.InnerException, "#10");
			}
		}
 /// <summary>
 /// 重置服务
 /// </summary>
 private void ResetService()
 {
     CommiManager mgr = CommiManager.GlobalManager;
     CommiTarget target = getService();
     CommandBase cmdbeat = CmdFileTrans.OpenHeaderBeat(mgr, target);
     if (cmdbeat.EventWh.WaitOne(25000, false))
         return;
     //无心跳则重启
     ServiceController ctrl = new ServiceController("Granity服务守护");
     ctrl.ExecuteCommand(200);
     Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 重启Granity文件服务");
     myLog.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " 重启Granity文件服务");
 }
Beispiel #30
0
 static void Main(string[] args)
 {
     try
     {
         ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policy) =>
         {
             return true;
         };
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     /*
      * Zisti ci treba obnovit shortcuty alebo nainstalovat balik
      */
     string installDir;
     bool error = false;
     if (args.Length > 0)
     {
         if (args.Length > 1)
         {
             executable = args[1];
         }
         if (args.Length < 2 || !File.Exists(executable)) {
             installDir = (string)Registry.GetValue(keyName, "installDir", "Not Exist");
             package = args[0];
             // zapis balik ktory treba nainstalovat
             File.WriteAllText(installDir + "Last.txt", package);
             // zavolaj sluzbu a povedz je ze treba nainstalovat balik
             ServiceController sc = new ServiceController("SetItUpService");
             sc.ExecuteCommand(SERVICE_INSTALL_PACKAGE);
             error = WaitForService(installDir);
         }
             // ked sluzba nainstaluje balik a do parametru sme dostali .exe programu, tak ho spustime
         if (args.Length > 1 && !error)
         {
             //executable = args[1];
             var handle = GetConsoleWindow();
             // Hide
             ShowWindow(handle, SW_HIDE);
             var proc = new Process();
             try
             {
                 proc.StartInfo.FileName = executable;
                 //proc.StartInfo.UseShellExecute = false;
                 try
                 {
                     proc = Process.Start(executable);
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine("Nastala chyba pri spusteni programu " + ex.Message);
                     Console.ReadKey();
                     return;
                 }
                 if (proc != null) proc.WaitForExit();
             }
             finally
             {
                 if (proc != null) proc.Dispose();
             }
         }
         else
         {
             Console.WriteLine("Nepodarilo sa nainstalovat " + package);
             Console.ReadKey();
         }
     }
     else
     {
         // ideme updatovat, skontrolujeme/nastavime registry
         string packageDir;
         string shortcutDir;
         string serverDir;
         RegistryKey key;
         try
         {
             key = Registry.LocalMachine.CreateSubKey("SOFTWARE");
             key = key.CreateSubKey("SetItUp");
             packageDir = (string)Registry.GetValue(keyName, "packageDir", "Not Exist");
             if (packageDir == "Not Exist")
             {
                 FolderBrowserDialog aaa = new FolderBrowserDialog();
                 aaa.ShowDialog();
                 key = Registry.LocalMachine.OpenSubKey("Software", true);
                 key = key.CreateSubKey("SetItUp");
                 key.SetValue("packageDir", aaa.SelectedPath + "\\");
                 packageDir = (string)Registry.GetValue(keyName, "packageDir", "Not Exist");
             }
             shortcutDir = (string)Registry.GetValue(keyName, "shortcutDir", "Not Exist");
             if (shortcutDir == "Not Exist")
             {
                 FolderBrowserDialog aaa = new FolderBrowserDialog();
                 aaa.ShowDialog();
                 key = Registry.LocalMachine.OpenSubKey("Software", true);
                 key = key.OpenSubKey("SetItUp", true);
                 key.SetValue("shortcutDir", aaa.SelectedPath + "\\");
                 shortcutDir = (string)Registry.GetValue(keyName, "shortcutDir", "Not Exist");
             }
             serverDir = (string)Registry.GetValue(keyName, "serverDir", "Not Exist");
             if (serverDir == "Not Exist")
             {
                 Form1 aaa = new Form1();
                 aaa.StartPosition = FormStartPosition.CenterParent;
                 aaa.ShowDialog();
                 key = Registry.LocalMachine.OpenSubKey("Software", true);
                 key = key.OpenSubKey("SetItUp", true);
                 key.SetValue("serverDir", aaa.getData());
                 serverDir = (string)Registry.GetValue(keyName, "serverDir", "Not Exist");
             }
             installDir = (string)Registry.GetValue(keyName, "installDir", "Not Exist");
             if (installDir == "Not Exist")
             {
                 key = Registry.LocalMachine.OpenSubKey("Software", true);
                 key = key.OpenSubKey("SetItUp", true);
                 key.SetValue("installDir", Application.StartupPath);
                 installDir = (string)Registry.GetValue(keyName, "installDir", "Not Exist");
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine("Nastala chyba pri narabani s registrami " + ex.Message + Environment.NewLine);
             Console.ReadKey();
             return;
         }
     }
 }