private bool CallProgramAsAdmin(string path, string arguments) { var result = _shellExecuteHelper.RunAsAdmin(path, arguments); if (result == ShellExecuteResult.RunAsWasDenied) { var message = _translation.SufficientPermissions; var caption = _translation.Error; ShowMessage(message, caption, MessageOptions.OK, MessageIcon.Error); return(false); } return(result == ShellExecuteResult.Success); }
public bool TryRepairPrinter(IEnumerable <string> printerNames) { Logger.Error("It looks like the printers are broken. This needs to be fixed to allow PDFCreator to work properly"); var title = _translation.RepairPrinterNoPrintersInstalled; var message = _translation.RepairPrinterAskUserUac; Logger.Debug("Asking to start repair.."); var response = ShowMessage(message, title, MessageOptions.YesNo, MessageIcon.Exclamation); if (response == MessageResponse.Yes) { var applicationPath = _assemblyHelper.GetAssemblyDirectory(); var printerHelperPath = _pathSafe.Combine(applicationPath, "PrinterHelper.exe"); if (!_file.Exists(printerHelperPath)) { Logger.Error("PrinterHelper.exe does not exist!"); title = _translation.Error; message = _translation.GetSetupFileMissingMessage(_pathSafe.GetFileName(printerHelperPath)); ShowMessage(message, title, MessageOptions.OK, MessageIcon.Error); return(false); } Logger.Debug("Reinstalling Printers..."); var pdfcreatorPath = _nameProvider.GetPortApplicationPath(); var printerNameString = GetPrinterNameString(printerNames); var installParams = $"/RepairPrinter {printerNameString} /PortApplication \"{pdfcreatorPath}\""; var installResult = _shellExecuteHelper.RunAsAdmin(printerHelperPath, installParams); Logger.Debug("Done: {0}", installResult); } Logger.Debug("Now we'll check again, if the printer is installed"); if (IsRepairRequired()) { Logger.Warn("The printer could not be repaired."); return(false); } Logger.Info("The printer was repaired successfully"); return(true); }
public void TryRepairSpoolPath() { Logger.Error( "The spool folder is not accessible due to a permission problem. PDFCreator will not work this way"); var username = _environment.UserName; Logger.Debug("UserName is {0}", username); var title = _translator.GetTranslation("Application", "SpoolFolderAccessDenied"); var message = _translator.GetFormattedTranslation("Application", "SpoolFolderAskToRepair", _tempFolder); Logger.Debug("Asking to start repair.."); if (ShowMessage(message, title, MessageOptions.YesNo, MessageIcon.Exclamation) == MessageResponse.Yes) { var repairToolPath = _assemblyHelper.GetPdfforgeAssemblyDirectory(); repairToolPath = _path.Combine(repairToolPath, "RepairFolderPermissions.exe"); var repairToolParameters = $"\"{username}\" \"{_tempFolder}\""; Logger.Debug("RepairTool path is: {0}", repairToolPath); Logger.Debug("Parameters: {0}", repairToolParameters); if (!_file.Exists(repairToolPath)) { Logger.Error("RepairFolderPermissions.exe does not exist!"); title = _translator.GetTranslation("Application", "RepairToolNotFound"); message = _translator.GetFormattedTranslation("Application", "SetupFileMissing", _path.GetFileName(repairToolPath)); ShowMessage(message, title, MessageOptions.OK, MessageIcon.Error); return; } Logger.Debug("Starting RepairTool..."); var result = _shellExecuteHelper.RunAsAdmin(repairToolPath, repairToolParameters); Logger.Debug("Done: {0}", result); } }