private void ShowSettingsWindow() { List <Device> HIDList = new List <Device>(); string currentHardwareId = null; while (true) { try { // Establish a new connection to the Windows service if there isn't one available to complete the action if (TTService == null) { if (InitialiseServiceConnection()) { continue; // retry } else { return; // failed, abort action } } // Perform the enable/disable action HIDList = TTService.GetHumanInterfaceDevices(); // Get the currently selected hardware ID currentHardwareId = TTService.GetSelectedHardwareID(); break; } catch (CommunicationException) { if (!ServiceCommunicationFailure()) { return; } } } SettingsWindow settingsWindow = new SettingsWindow(HIDList, currentHardwareId, (hardwareId) => { string servicePath = PathHelper.GetPathToApplicationComponent(PathHelper.ApplicationComponent.ServiceExecutable); Process process; try { process = ProcessHelper.StartAdminProcess(servicePath, "settouchdeviceid \"" + Strings.Base64Encode(hardwareId) + "\""); } catch (ProcessCancelledException) { return(SettingsWindow.SaveResult.AbortedUAC); } catch (FIleNotFoundException) { return(SettingsWindow.SaveResult.Error); } while (!process.WaitForExit(5000)) { // Wait } if (process.ExitCode != 0) { return(SettingsWindow.SaveResult.Error); } GetTouchDeviceStatus(); return(SettingsWindow.SaveResult.Success); }); settingsWindow.Focus(); settingsWindow.ShowDialog(); }