;=============================================================================== ; ; Function Name: _PrinterAdd() ; Description: Connects to a Network Printer. ; Parameter(s): $sPrinterName - Computer Network name and printer share name (\\Computer\SharedPrinter). ; $fDefault - Set to 1 if Printer should be set to default (optional). ; Requirement(s): ; Return Value(s): 1 - Success, 0 - Failure, If Printer already exist @error = 1. ; Author(s): Sven Ullstad - Wooltown ; Note(s): None. ; ;=============================================================================== Func _PrinterAdd($sPrinterName, $fDefault = 0) If _PrinterExist($sPrinterName) Then SetError(1) Return 0 Else RunWait ("rundll32 printui.dll,PrintUIEntry /in /n" & $sPrinterName & " /q") If _PrinterExist($sPrinterName) = 0 Then Return 0 EndIf If $fDefault = 1 Then _PrinterDefault($sPrinterName) EndIf Return 1 EndIf EndFunc ;=============================================================================== ; ; Function Name: _PrinterDefault() ; Description: Set a printer to default. ; Parameter(s): $sPrinterName - The name of the printer. ; Requirement(s): ; Return Value(s): 1 - Success, 0 - Failure. ; Author(s): Sven Ullstad - Wooltown ; Note(s): None. ; ;=============================================================================== Func _PrinterDefault($sPrinterName) If _PrinterExist($sPrinterName) Then RunWait ("rundll32 printui.dll,PrintUIEntry /y /n" & $sPrinterName) Return 1 Else Return 0 EndIf EndFunc ;=============================================================================== ; ; Function Name: _PrinterDelete() ; Description: Delete a connection to a network printer. ; Parameter(s): $sPrinterName - Computer Network name and printer share name. ; Requirement(s): ; Return Value(s): 1 - Success, 0 - Failure. ; Author(s): Sven Ullstad - Wooltown ; Note(s): None. ; ;=============================================================================== Func _PrinterDelete($sPrinterName) If _PrinterExist($sPrinterName) Then RunWait ("rundll32 printui.dll,PrintUIEntry /dn /n" & $sPrinterName) If _PrinterExist($sPrinterName) Then Return 0 Else Return 1 EndIf Else Return 0 EndIf EndFunc ;=============================================================================== ; ; Function Name: _PrinterExist() ; Description: Check if a Printer Exist. ; Parameter(s): $sPrinterName - The name of the printer. ; Requirement(s): ; Return Value(s): 1 - Success, 0 - Failure. ; Author(s): Sven Ullstad - Wooltown ; Note(s): None. ; ;=============================================================================== Func _PrinterExist($sPrinterName) Local $hService, $sPrinter, $sPrinterList $hService = ObjGet ("winmgmts:{impersonationLevel=impersonate}!" & "\\" & @ComputerName & "\root\cimv2") If Not @error = 0 Then Return 0 EndIf $sPrinterList = $hService.ExecQuery ("Select * From Win32_Printer") For $sPrinter In $sPrinterList If StringUpper($sPrinterName) = StringUpper($sPrinter.name) Then Return 1 EndIf Next EndFunc