Adding Port, Driver, Printer in Windows
Posted: Sun Jan 22, 2017 4:18 pm
I have been trying to programmatically setup a virtual printer with some API functions but have been very very unsuccessful. This is what I've got so far although the first part doesn't work. The last part for adding the printer works only if the driver is already (manually) installed:
Is anyone familiar with the AddMonitor, AddPort and AddPrinterDriver parts?
Any help is appreciated. Thank you.
Code: Select all
Define mon.MONITOR_INFO_2, drv.DRIVER_INFO_3, prn.PRINTER_INFO_2
With mon
\pEnvironment = @""
\pName = @"newMonitor"
;not sure what DLL should be used here
\pDLLName = @"?.dll"
EndWith
;also tried with the full path - C:\Windows\System32\DriverStore\FileRepository
With drv
\cVersion = 3
\pDriverPath = @"\driverPath\PSCRIPT5.DLL"
\pConfigFile = @"\driverPath\PS5UI.DLL"
\pHelpFile = @"\driverPath\PSCRIPT.HLP"
\pDataFile = @"\driverPath\MSXPSINC.PPD"
\pDependentFiles = @"\driverPath\PSCRIPT.NTF"
\pEnvironment = @"Windows NT x86"
\pName = @"Miscrosoft PS Class Driver"
EndWith
With prn
\pServerName = @""
\pPrinterName = @"myPrinter"
\pDriverName = @"Microsoft PS Class Driver"
\pPortName = @"e:\printJobs\file.ps"
\pPrintProcessor = @"WinPrint"
\Priority = 1
\DefaultPriority = 1
\pDatatype = @"RAW"
\pShareName = @"myPrinter"
\pComment = @"myPrinter File Capture"
\pLocation = @"local computer"
\Attributes = #PRINTER_ATTRIBUTE_LOCAL | #PRINTER_ATTRIBUTE_SHARED
EndWith
;need these 3 functions to install the printer driver
AddMonitor_(#Null$, 2, @mon)
AddPort_(#Null, #Null, @"newMonitor")
AddPrinterDriver_(#Null, 3, @drv)
;this works if the printer driver is already installed
AddPrinter_(#Null, 2, @prn)

Any help is appreciated. Thank you.