ds10025 Posted February 13, 2007 Share Posted February 13, 2007 Hi I'm in the process of writing a script that that allows users to install local printer drivers for our network. I can now install local printers drivers using Run() with runndll32. I want to use Auoit to ccheck if the printer driver is already installed or not. EG if printer name " HP laserjet 4100 PS" and LPT2: is mapped to the printer. Then Display "printer already installed" Else Install the printer driver and assign LPT2: to the printer. Any ideas? Link to comment Share on other sites More sharing options...
ptrex Posted February 13, 2007 Share Posted February 13, 2007 @ds10025 expandcollapse popup#include <Array.au3> ;Global Variables Const $wbemFlagReturnImmediately = 0x10 Const $wbemFlagForwardOnly = 0x20 Const $strComputer = "." $count = 0 $sHold = "" $array = "" ;HOW TO USE: ;$ARRAY = Enumprinter() Func EnumPrinter() local $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems If $objitem.DeviceID <> "" Then $sHold = $sHold & $objItem.DeviceID & "," $count = $count + 1 Endif Next If $sHold = "" Then Return $sHold else $array = StringSplit($sHold,",") _ArrayDelete($array,$count + 1) _arrayDelete($array,0) Return $array EndIf Endif EndFunc ; HOW TO USE: ; $DefaultPrinter = DefaultPrinter() ; Will return the default printer name if it doesnt have a ; Default printer it will return 0 Func DefaultPrinter() Local $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Printer", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems ;msgbox(0,"",$Objitem.Default) If $objitem.Default <> 0 Then $result = $objItem.DeviceID ;MsgBox(0,"",$objitem.deviceID) Return $result Endif Next Endif Return 0 EndFunc ;Add A global printer for all profiles ; $default 1=Default use either "" blank statement or 0 Func AddGlobalPrinter($Server,$Printer,$Default) Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /ga /n\\" & $Server & "\" & $printer,"",@SW_HIDE) RestartPrintSpool() If $Default = 1 Then ;msgbox(0,"",$printer) SetDefault("\\" & $Server & "\" & $Printer) ;RestartPrintSpool() Elseif $Default = 0 Then Elseif $Default = "" Then EndIF EndFunc ;Remove Printer that was added by AddGlobalPrinter func otherwise if printer ;was installed manual it will fail Func RemoveGlobalPrinter($Server,$Printer) Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /n\\" & $Server & "\" & $printer,"",@SW_HIDE) RestartPrintSpool() EndFunc ;Set the Default Printer Func SetDefault($Printer) Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " & $Printer , "",@SW_HIDE) EndFunc ;Helper function for restarting of print spooler Func RestartPrintSpool() local $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name = 'Spooler'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems ; msgbox(0,"",$objitem.Name) If $objitem.State = "Running" Then msgbox(0,"",$ObjItem.state) $some = $objItem.StopService() sleep(5000) $some1 = $objItem.StartService() ElseIF $objitem.State = "Stopped" Then ; msgbox(0,"",$ObjItem.state) $ObjItem.StartService() EndIf Next EndIf EndFunc Maybe this can get you started. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
ds10025 Posted February 14, 2007 Author Share Posted February 14, 2007 Great! Thanks. This will get me started. Link to comment Share on other sites More sharing options...
JohnBailey Posted February 20, 2007 Share Posted February 20, 2007 ptrex, great class! How come I can't set the default to be networked printer? I used $ARRAY = Enumprinter() _ArrayDisplay($ARRAY,"Printers") ControlSend("Untitled - Notepad","","Edit1",$ARRAY[7]) to obtain the name of the printer I want. However, when I set the default using that printer name I get an error telling me basically that the name is wrong. SetDefault("\\WEB_SERVER\hp LaserJet 2420 PCL6") A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted February 20, 2007 Share Posted February 20, 2007 By looking at http://www.autoitscript.com/forum/index.php?showtopic=29127 I found out that adjusting your script to Run(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /q /y /n " & '"' & $Printer & '"', "", @SW_HIDE)fromRun(@ComSpec & " /c RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " & $Printer , "",@SW_HIDE)works, but I don't know why. What does the added quotations and /q mean? A decision is a powerful thing Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now