public IPBanWindowsServiceRunner(IPBanServiceRunner runner, string[] args) { runner.ThrowIfNull(); try { Logger.Warn("Running as a Windows service"); this.runner = runner; CanShutdown = false; Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); } catch (Exception ex) { Logger.Error(ex); } }
public IPBanWindowsServiceRunner(IPBanServiceRunner runner, string[] args) { runner.ThrowIfNull(); try { Logger.Warn("Running as a Windows service"); this.runner = runner; CanShutdown = false; CanStop = CanHandleSessionChangeEvent = CanHandlePowerEvent = true; var acceptedCommandsField = typeof(ServiceBase).GetField("acceptedCommands", BindingFlags.Instance | BindingFlags.NonPublic); if (acceptedCommandsField != null) { int acceptedCommands = (int)acceptedCommandsField.GetValue(this); acceptedCommands |= 0x00000100; // SERVICE_ACCEPT_PRESHUTDOWN; acceptedCommandsField.SetValue(this, acceptedCommands); } Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); } catch (Exception ex) { Logger.Error(ex); } }