private void btnValidateGeneral_Click(object sender, RoutedEventArgs e) { MessageFolder = ""; try { //try writing to selected path string tmpFile = Path.Combine(General.LocalFolder, "test.txt"); File.WriteAllText(tmpFile, "File created to check write access for this folder."); //try deleting from selected path File.Delete(tmpFile); GeneralSettingHelper generalHelper = new GeneralSettingHelper(); generalHelper.SaveConfig(General); RaisePropertyChanged("General"); MessageFolder = "Settings successfully updated"; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("The selected path is not writable. Make sure the path is writable. \n" + message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void btnUninstallService_Click(object sender, RoutedEventArgs e) { try { //Stop the service ServiceController service = new ServiceController("Runtime Backup Service", "."); if (service != null && service.Status != ServiceControllerStatus.Stopped) service.Stop(); //Remove Registry Entry ProcessStartInfo startInfoDelete = new ProcessStartInfo { FileName = "sc.exe", Arguments = "delete \"Runtime Backup Service\"", CreateNoWindow = true, UseShellExecute = true }; Process processDelete = new Process() { StartInfo = startInfoDelete }; processDelete.Start(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to uninstall the service. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } //update status anyways //sometimes service is already uninstalled and above attempt will fail. So need to update status try { ServiceStatus = "Background service is not installed"; ServiceColor = "LightGray"; GeneralSettingHelper generalHelper = new GeneralSettingHelper(); GeneralSetting generalSetting = generalHelper.GetConfig(); if (generalSetting != null) { generalSetting.ServiceInstalled = false; generalHelper.SaveConfig(generalSetting); } btnInstallService.Visibility = Visibility.Visible; btnUnInstallService.Visibility = Visibility.Collapsed; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to update service status. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void btnInstallService_Click(object sender, RoutedEventArgs e) { try { string servicePath = EnVar.AppPath + "rbs.exe"; if (!File.Exists(servicePath)) { MessageBox.Show("Unable to find service. Try reinstalling the application.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } ProcessStartInfo startInfoRegistry = new ProcessStartInfo { FileName = "sc.exe", Arguments = "create \"Runtime Backup Service\" binpath=\"" + servicePath + "\" start=auto ", CreateNoWindow = true, UseShellExecute = true }; Process processRegistry = new Process() { StartInfo = startInfoRegistry }; processRegistry.Start(); await Task.Delay(2000); //Start the service ServiceController service = new ServiceController("Runtime Backup Service", "."); if (service != null && service.Status != ServiceControllerStatus.Running) service.Start(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to install the service. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { ServiceStatus = "Service is installed"; ServiceColor = "Green"; GeneralSettingHelper generalHelper = new GeneralSettingHelper(); GeneralSetting generalSetting = generalHelper.GetConfig(); if (generalSetting != null) { generalSetting.ServiceInstalled = true; generalHelper.SaveConfig(generalSetting); } btnInstallService.Visibility = Visibility.Collapsed; btnUnInstallService.Visibility = Visibility.Visible; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("Failed to update service status. \n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }