private bool InstallPdfScribePrinterDriver() { bool pdfScribePrinterDriverInstalled = false; if (!IsPrinterDriverInstalled(DRIVERNAME)) { String driverSourceDirectory = RetrievePrinterDriverDirectory(); StringBuilder nullTerminatedDependentFiles = new StringBuilder(); if (printerDriverDependentFiles.Length > 0) { for (int loop = 0; loop <= printerDriverDependentFiles.GetUpperBound(0); loop++) { nullTerminatedDependentFiles.Append(printerDriverDependentFiles[loop]); nullTerminatedDependentFiles.Append("\0"); } nullTerminatedDependentFiles.Append("\0"); } else { nullTerminatedDependentFiles.Append("\0\0"); } DRIVER_INFO_6 printerDriverInfo = new DRIVER_INFO_6(); printerDriverInfo.cVersion = 3; printerDriverInfo.pName = DRIVERNAME; printerDriverInfo.pEnvironment = ENVIRONMENT_64; printerDriverInfo.pDriverPath = Path.Combine(driverSourceDirectory, DRIVERFILE); printerDriverInfo.pConfigFile = Path.Combine(driverSourceDirectory, DRIVERUIFILE); printerDriverInfo.pHelpFile = Path.Combine(driverSourceDirectory, DRIVERHELPFILE); printerDriverInfo.pDataFile = Path.Combine(driverSourceDirectory, DRIVERDATAFILE); printerDriverInfo.pDependentFiles = nullTerminatedDependentFiles.ToString(); printerDriverInfo.pMonitorName = PORTMONITOR; printerDriverInfo.pDefaultDataType = String.Empty; printerDriverInfo.dwlDriverVersion = 0x0000000200000000U; printerDriverInfo.pszMfgName = DRIVERMANUFACTURER; printerDriverInfo.pszHardwareID = HARDWAREID; printerDriverInfo.pszProvider = DRIVERMANUFACTURER; pdfScribePrinterDriverInstalled = InstallPrinterDriver(ref printerDriverInfo); } else { pdfScribePrinterDriverInstalled = true; // Driver is already installed, we'll just use the installed driver } return(pdfScribePrinterDriverInstalled); }
private bool InstallPrinterDriver(ref DRIVER_INFO_6 printerDriverInfo) { bool printerDriverInstalled = false; printerDriverInstalled = NativeMethods.AddPrinterDriver(null, 6, ref printerDriverInfo); if (printerDriverInstalled == false) { //int lastWinError = Marshal.GetLastWin32Error(); //throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not add printer PDF Scribe printer driver."); logEventSource.TraceEvent(TraceEventType.Error, (int)TraceEventType.Error, "Could not add PDF Scribe printer driver. " + String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString())); } return(printerDriverInstalled); }
internal static extern bool AddPrinterDriver(String pName, int Level, ref DRIVER_INFO_6 pDriverInfo);