Not sure how it work, but I have some code that does it. This stuff's about as fubbed duck as a football bat:
Routine Code:
Module Code:Code:Const ERROR_PRINTER_ALREADY_EXISTS = 1802 Const PRINTER_NAME = "Generic / Text Only" Const PORT_NAME = "FILE:" Const DRIVER_NAME = "Generic / Text Only" Const PRINT_PROCESSOR = "winprint" Const DATA_TYPE = "TEXT" Const DATA_FILE = "Txtonly.dll" Const DRIVER_FILE = "Rasdd.dll" Const CONFIG_FILE = "Rasddui.dll" Const HELP_FILE = "Rasddui.hlp" Const ENVIRONMENT = "Windows NT x86" Dim hpHandle As Long Dim lError As Long Dim lResult As Long Dim sDriverBuf As String * Max_Path Dim sDriverPath As String Dim lPathSize As Long On Error GoTo AddPrinterError ' First we get the folder for the printer driver files lResult = GetPrinterDriverDirectory(vbNullString, vbNullString, 1&, _ sDriverBuf, Max_Path, lPathSize) If (lResult = 0) Then ErrorHandler "Unable to retrieve the printer driver folder.", Err.LastDllError End If lResult = InStr(sDriverBuf, Chr$(0)) sDriverPath = Left$(sDriverBuf, lResult - 1) If (Right$(sDriverPath, 1) <> "\") Then sDriverPath = sDriverPath & "\" ' Next we copy the required printer files to that folder If (CopyFile(App.Path & "\" & DATA_FILE, sDriverPath & DATA_FILE, False) = 0) Then ErrorHandler "Unable to copy the required printer driver files (Data).", Err.LastDllError End If If (Dir(sDriverPath & DATA_FILE, vbReadOnly) <> "") Then SetAttr sDriverPath & DATA_FILE, vbNormal End If If (CopyFile(App.Path & "\" & DRIVER_FILE, sDriverPath & DRIVER_FILE, False) = 0) Then ErrorHandler "Unable to copy the required printer driver files (Driver).", Err.LastDllError End If If (Dir(sDriverPath & DRIVER_FILE, vbReadOnly) <> "") Then SetAttr sDriverPath & DRIVER_FILE, vbNormal End If If (CopyFile(App.Path & "\" & CONFIG_FILE, sDriverPath & CONFIG_FILE, False) = 0) Then ErrorHandler "Unable to copy the required printer driver files (Config).", Err.LastDllError End If If (Dir(sDriverPath & CONFIG_FILE, vbReadOnly) <> "") Then SetAttr sDriverPath & CONFIG_FILE, vbNormal End If If (CopyFile(App.Path & "\" & HELP_FILE, sDriverPath & HELP_FILE, False) = 0) Then ErrorHandler "Unable to copy the required printer driver files (Help).", Err.LastDllError End If If (Dir(sDriverPath & HELP_FILE, vbReadOnly) <> "") Then SetAttr sDriverPath & HELP_FILE, vbNormal End If 'Add the Printer Driver. This will configure the printer driver. udtDriverInfo.cVersion = 2& udtDriverInfo.pName = PRINTER_NAME udtDriverInfo.pEnvironment = ENVIRONMENT udtDriverInfo.pDriverPath = sDriverPath & DRIVER_FILE udtDriverInfo.pDataFile = sDriverPath & DATA_FILE udtDriverInfo.pConfigFile = sDriverPath & CONFIG_FILE udtDriverInfo.pHelpFile = sDriverPath & HELP_FILE udtDriverInfo.pDependentFiles = DATA_FILE & Chr$(0) & _ DRIVER_FILE & Chr$(0) & _ CONFIG_FILE & Chr$(0) & _ HELP_FILE & Chr$(0) & Chr$(0) udtDriverInfo.pMonitorName = vbNullString udtDriverInfo.pDefaultDataType = DATA_TYPE lResult = AddPrinterDriver(vbNullString, 3&, udtDriverInfo) If (lResult = 0) Then ErrorHandler "Unable to configure Generic printer driver.", Err.LastDllError End If ' Now we can add the printer udtPrinterInfo.pServerName = vbNullString udtPrinterInfo.pPrinterName = PRINTER_NAME udtPrinterInfo.pPortName = PORT_NAME udtPrinterInfo.pDriverName = DRIVER_NAME udtPrinterInfo.pPrintProcessor = PRINT_PROCESSOR udtPrinterInfo.pDatatype = DATA_TYPE hpHandle = AddPrinter(vbNullString, 2&, udtPrinterInfo) If (hpHandle) Then ClosePrinter (hpHandle) Else lError = Err.LastDllError If (lError <> ERROR_PRINTER_ALREADY_EXISTS) Then ErrorHandler "Unable to install Generic printer.", lError End If End If
Maybe one of the gurus can explain how this works...Code:Private Type PRINTER_INFO_2 pServerName As String pPrinterName As String pShareName As Long pPortName As String pDriverName As String pComment As Long pLocation As Long pDevMode As Long ' Pointer to DEVMODE pSepFile As Long pPrintProcessor As String pDatatype As String pParameters As Long pSecurityDescriptor As Long ' Pointer to SECURITY_DESCRIPTOR Attributes As Long Priority As Long DefaultPriority As Long StartTime As Long UntilTime As Long Status As Long cJobs As Long AveragePPM As Long End Type Private udtPrinterInfo As PRINTER_INFO_2




Reply With Quote