|
![]() |
| Printer Installation |
The following code is used to create a package which creates a printer queue using "prnadmin.dll" (free MS tool). This will only work on WIN2000+.
As written the code doesn't do anything if the queue already exists, another option might be to delete or update the existing queue. However if deleting would you delete jobs on queue, if not then what?
You would need to ensure that "prnadmin.dll" was already installed or install it (register) as part of your package.
Also check out the "printui.dll,PrintUIEntry" options available (this was used for the Printer Driver Installation example).
;--- Main Attributes --------------------------------------------------------
#define QUEUE_NAME HP DeskJet 430
#define PORT_NAME LPT1:
#define DRIVER_NAME HP Deskjet 430 printer
;--- Load MAKEMSI (via wrapper) ---------------------------------------------
#include "ME.MMH"
;--- Create the code --------------------------------------------------------
<$VbsCa Binary="CreatePrinterQueueIfRequired.vbs">
;--- Global variables ----------------------------------------------------
dim oMaster, oPrinter
;--- Entry point ---------------------------------------------------------
<$VbsCaEntry "CreatePrinterQueueIfRequired">
;--- Initialization --------------------------------------------------
set oMaster = CreatePrinterObject("PrintMaster.PrintMaster.1")
set oPrinter = CreatePrinterObject("Printer.Printer.1")
;--- Create the printer if it doesn't already exist ------------------
if not QueueExists("<$QUEUE_NAME>") then
CreateQueue("<$QUEUE_NAME>")
else
CaDebug 0,"Not creating the queue (if you want to recreated the queue manually delete it first)"
end if
<$/VbsCaEntry>
<?NewLine>
'============================================================================
function CreatePrinterObject(ObjectId)
'
' Creates required object or aborts install with decent message
'============================================================================
CaDebug 0,"CreatePrinterObject(""" & ObjectId & """)"
on error resume next
set CreatePrinterObject = CreateObject(ObjectId)
if err.number <> 0 then
;--- FAILED ------------------------------------------------------
dim T : T = "Failed to create """ & ObjectId & """. The most likely reason is if ""prnadmin.dll"" is not available." & vbCRLF & vbCRLF & "Error Information: " & err.description
on error goto 0
VbsCaRaiseError "CreatePrinterObject()", T
end if
CaDebug 0,"Successfully created the object (""" & ObjectId & """)"
end function
<?NewLine>
'============================================================================
function QueueExists(QueueName)
'
' Checks if a named printer queue already exists
'============================================================================
CaDebug 0,"QueueExists(""" & QueueName & """)"
on error resume next
oMaster.PrinterGet "", QueueName, oPrinter ;;Query works with any case queue name
if err.number = 0 then
QueueExists = true
CaDebug 0,"Printer Queue """ & QueueName & """ exists."
else
QueueExists = false
CaDebug 0,"Printer Queue """ & QueueName & """ does not exist."
end if
err.clear()
end function
<?NewLine>
'============================================================================
sub CreateQueue(QueueName)
'
' Creates a queue, see "prnadmin.doc" for more details.
'============================================================================
on error resume next
CaDebug 0,"CreateQueue(""" & QueueName & """)"
oPrinter.PrinterName = QueueName
oPrinter.PortName = "<$PORT_NAME>"
oPrinter.DriverName = "<$DRIVER_NAME>"
oPrinter.Comment = "Created by '<$ProdInfo.ProductName>' version <$ProductVersion> at " & date() & ", " & time()
oPrinter.Location = "<$PORT_NAME>"
oMaster.PrinterAdd oPrinter
oMaster.PrinterSet oPrinter
if err.number <> 0 then
;--- FAILED ------------------------------------------------------
dim T : T = "Failed to create """ & QueueName & """." & vbCRLF & vbCRLF & "Error Information: " & err.description
on error goto 0
VbsCaRaiseError "CreateQueue()", T
end if
CaDebug 0,"Successfully created the queue """ & QueueName & """"
end sub
<$/VbsCa>
;--- Schedule after files installed and any registration performed ----------
<$VbsCaSetup Binary="CreatePrinterQueueIfRequired.vbs" Entry="CreatePrinterQueueIfRequired" Seq="StartServices-" CONDITION=^<$CONDITION_EXCEPT_UNINSTALL>^>
![]() | ![]() |