public static bool AddPrinter(string name) { bool resultCode; clawPDFInstaller installer = new clawPDFInstaller(); try { if (installer.AddCustomclawPDFPrinter(name)) { resultCode = true; Spooler.stop(); Spooler.start(); } else { resultCode = false; } } finally { } return(resultCode); }
/// <summary> /// Adds the clawPDF port monitor /// </summary> /// <param name="monitorFilePath">Directory where the uninstalled monitor dll is located</param> /// <returns>true if the monitor is installed, false if install failed</returns> public bool AddclawPDFPortMonitor(String monitorFilePath) { bool monitorAdded = false; IntPtr oldRedirectValue = IntPtr.Zero; try { oldRedirectValue = DisableWow64Redirection(); //if (!DoesMonitorExist(PORTMONITOR)) //{ // Copy the monitor DLL to // the system directory String monitorfileSourcePath = Path.Combine(monitorFilePath, MONITORDLL); String monitorfileDestinationPath = Path.Combine(Environment.SystemDirectory, MONITORDLL); String monitoruifileSourcePath = Path.Combine(monitorFilePath, MONITORUIDLL); String monitoruifileDestinationPath = Path.Combine(Environment.SystemDirectory, MONITORUIDLL); Spooler.stop(); try { File.Copy(monitoruifileSourcePath, monitoruifileDestinationPath, true); } catch { } try { File.Copy(monitorfileSourcePath, monitorfileDestinationPath, true); } catch { } Spooler.start(); MONITOR_INFO_2 newMonitor = new MONITOR_INFO_2(); newMonitor.pName = PORTMONITOR; newMonitor.pEnvironment = ENVIRONMENT; newMonitor.pDLLName = MONITORDLL; if (!AddPortMonitor(newMonitor)) { Console.WriteLine(String.Format("Could not add port monitor {0}", PORTMONITOR) + Environment.NewLine + String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString())); } else { monitorAdded = true; } //} //else //{ // Monitor already installed - // log it, and keep going // Console.WriteLine(String.Format("Port monitor {0} already installed.", PORTMONITOR)); // monitorAdded = true; // } } finally { if (oldRedirectValue != IntPtr.Zero) { RevertWow64Redirection(oldRedirectValue); } } return(monitorAdded); }