diff --git a/src/modules/MouseWithoutBorders/App/Class/Program.cs b/src/modules/MouseWithoutBorders/App/Class/Program.cs index ddeeeaae3a..964d0b1d3a 100644 --- a/src/modules/MouseWithoutBorders/App/Class/Program.cs +++ b/src/modules/MouseWithoutBorders/App/Class/Program.cs @@ -86,15 +86,25 @@ namespace MouseWithoutBorders.Class // If we're started from the .dll module or from the service process, we should // assume the service mode. - if (serviceMode || runningAsSystem) + if (serviceMode && !runningAsSystem) { - if (!runningAsSystem) + try { var sc = new ServiceController(ServiceName); sc.Start(); return; } + catch (Exception ex) + { + Common.Log("Couldn't start the service. Will try to continue as not a service."); + Common.Log(ex); + serviceMode = false; + Setting.Values.UseService = false; + } + } + if (serviceMode || runningAsSystem) + { if (args.Length > 2) { Helper.UserLocalAppDataPath = args[2].Trim(); diff --git a/src/modules/MouseWithoutBorders/App/Class/Setting.cs b/src/modules/MouseWithoutBorders/App/Class/Setting.cs index 12a37008ce..e3699a0766 100644 --- a/src/modules/MouseWithoutBorders/App/Class/Setting.cs +++ b/src/modules/MouseWithoutBorders/App/Class/Setting.cs @@ -979,6 +979,30 @@ namespace MouseWithoutBorders.Class } } + // If starting the service fails, work in not service mode. + internal bool UseService + { + get + { + lock (_loadingSettingsLock) + { + return _properties.UseService; + } + } + + set + { + lock (_loadingSettingsLock) + { + _properties.UseService = value; + if (!PauseInstantSaving) + { + SaveSettings(); + } + } + } + } + internal bool SendErrorLogV2 { get