Golbez Posted July 20, 2008 Share Posted July 20, 2008 my problem is my program only prints to the default printer. what if the default printer is a fax to an email, not an actual printer. $printfile = FileOpen(@ScriptDir & "\ProgFiles\print.txt", 2) FileWriteLine($printfile, "TESTING!!!" & @CRLF) FileClose($printfile) _FilePrint(@ScriptDir & "\print.txt") i need to somehow change the default printer but i have no clue how to do this.. can someone point me in the way please muttley i tried the search but didnt find anything that i thought was what i needed. Link to comment Share on other sites More sharing options...
Linux Posted July 20, 2008 Share Posted July 20, 2008 Or a away to get the printer list and selecting the printer muttley I know its an aspect of AutoIt that few have explored, but can someone give a hint to this mate pls? You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!" Link to comment Share on other sites More sharing options...
martin Posted July 20, 2008 Share Posted July 20, 2008 (edited) Or a away to get the printer list and selecting the printer muttley I know its an aspect of AutoIt that few have explored, but can someone give a hint to this mate pls? This might help. expandcollapse popupFunc GetPrinterList() Local $result, $strComputer, $colEvents, $np,$result $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents $result &= $objPrinter.DeviceID & '|' EndIf $Result = StringLeft($result,StringLen($result) - 1) Return $result;return the list of printers EndFunc Func GetDefaultPrinter() Local $szDefPrinterName Local $Size $namesize = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($namesize)) $pname = DllStructCreate("char[" & DllStructGetData($namesize, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($pname), "ptr", DllStructGetPtr($namesize)) Return DllStructGetData($pname, 1);msgbox(0,dllstructgetdata($namesize,1),DllStructGetData($pname,1)) EndFunc ;==>GetDefaultPrinter1 Func PrinterSetAsDefault($PrinterName) Local $result, $strComputer, $colEvents, $np If GetDefaultPrinter() = $PrinterName Then Return 1 $result = 0 $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents If $objPrinter.DeviceID = $PrinterName Then $objPrinter.SetDefaultPrinter() $result = 1 EndIf Next If $result Then GUICtrlSetData($IPCurrentDefault,$currentPrinter) EndIf Return $result EndFunc These things and more can also be done more easily with my printer udf and dll. There is a script I wrote in here which sets the printer automatically depending on the Active program which could be of interest, though the way of setting the printer is the same as the code above. Not tried it for a while so it might need some tweeks for the current AutoIt versions. EDIT: Removed duplicate function Edited October 10, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 will it still print in a txt file? Link to comment Share on other sites More sharing options...
martin Posted July 20, 2008 Share Posted July 20, 2008 will it still print in a txt file?Sorry, I don't understand that question. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 (edited) i need it to print a txt file that i generate...will it still print in a txt file?i meant to say will it still print a txt file Edited July 20, 2008 by Golbez Link to comment Share on other sites More sharing options...
martin Posted July 20, 2008 Share Posted July 20, 2008 (edited) i need it to print a txt file that i generate... i meant to say will it still print a txt fileI still don't understand. Will what still print a text file? How were you printing the text file? Are you using some application that prints the file or do you want to know how to print the file? Sorry, I assume you mean the script you posted at the start. Then the answer is yes, change the printer using the function I gave, then use the FilePrint and it will print on the printer you selected. $printfile = FileOpen(@ScriptDir & "\ProgFiles\print.txt", 2) FileWriteLine($printfile, "TESTING!!!" & @CRLF) FileClose($printfile) $defaultPrinter = GetDefaultPrinter() PrinterSetAsDefault("Epsom 9832");Set whatever printer you want _FilePrint(@ScriptDir & "\print.txt") PrinterSetAsDefault($defaultPrinter ):set back the original printer if you want to/need to Edited July 20, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 my problem is my program only prints to the default printer. what if the default printer is a fax to an email, not an actual printer. $printfile = FileOpen(@ScriptDir & "\ProgFiles\print.txt", 2) FileWriteLine($printfile, "TESTING!!!" & @CRLF) FileClose($printfile) _FilePrint(@ScriptDir & "\print.txt") i need to somehow change the default printer but i have no clue how to do this.. can someone point me in the way please muttley i tried the search but didnt find anything that i thought was what i needed. _FilePrint(@ScriptDir & "\print.txt") i need it to set the printer before it prints this Link to comment Share on other sites More sharing options...
martin Posted July 20, 2008 Share Posted July 20, 2008 _FilePrint(@ScriptDir & "\print.txt")i need it to set the printer before it prints thisI edited my previous post while you were writing that. I hope I have answered your question. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 (edited) it did alot.. 1 more question... the Func GetPrinterList() Local $result, $strComputer, $colEvents, $np,$result $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents $result &= $objPrinter.DeviceID & '|' EndIf $Result = StringLeft($result,StringLen($result) - 1) Return $result ;return the list of printers EndFuncoÝ÷ Ú)z¶Ø§ê뢻0Ømç§v'ÚÊ!£!¢é]ج¦V²¶«zË¥¶Ê¶¬~éܶ*'yØN¬"¦ër¢êܡעÚ&wëj·ç«®ìr^4÷e,z»4÷dZËOv.éí³Ov3#ë¢ ÚÍ=Øö«jz+©QzÇÈEW«ÓÝ©®)íz»^²Ö®ß6Ó5çÁDäyò̧µ¬^®º+wH|.|ÓݱêìÓÝk-=Ø:ºg§¶Í=ØÌ®+jk4÷cÚ©è®f¥Eëj·!)^¯Ov¦¸§µêízËZ»~4Ûx×EçË2Ö±zºè¬IÝéÜ4÷e,z»4÷dZËOv.éí³Ov3#ë¢ ÚÍ=Øö«jz+©QzÇÈEW«ÓÝ©®)íz»^²Ö®ß7ã^5çÁDäyò̧µ¬^®º+wEºwçÍ=ÙK®Í=Ù²Óݡ˦z{lÓÝÈú趦³Ov=ªÚæjT^±æ«rbêô÷jk{^®×¬µ«·ãNz×yðDQ9|³)ík«®ÄÑnÀ¹óOvRÇ«³OvE¬´÷`èréÛ4÷c2>º ©¬ÓÝj¶§¢¹¬yªÜX¥z½=Úâ׫µë-jíøÓûã^|NGzÐÞ}«¥´úâ׫ãN5ç˧uçâç_ºw-ôߧ^}«¥´úâ׫ Edited July 20, 2008 by Golbez Link to comment Share on other sites More sharing options...
martin Posted July 20, 2008 Share Posted July 20, 2008 The Endif in my script should have been Next. There was also an error in yours - the file you created was not in the @ScriptDir, and an include was missing. This has been tested, but you need to set the printer correctly. expandcollapse popup#Include <File.au3> Global $objWMIService, $IPCurrentDefault, $currentPrinter, $printer, $PrinterName $printfile = FileOpen(@ScriptDir & "\print.txt", 2) FileWriteLine($printfile, "TESTING!!!" & @CRLF) FileClose($printfile) $defaultPrinter = GetDefaultPrinter() ConsoleWrite($defaultprinter & @CRLF) $printer = $defaultprinter;<---------------------------set the printer here PrinterSetAsDefault($printer);Set whatever printer you want ConsoleWrite("Result of _FilePrint is " & _FilePrint(@ScriptDir & "\print.txt") & @CRLF) PrinterSetAsDefault($defaultPrinter);set back the original printer if you want to/need to Func GetPrinterList() Local $result, $strComputer, $colEvents, $np,$result $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents $result &= $objPrinter.DeviceID & '|' Next $Result = StringLeft($result,StringLen($result) - 1) Return $result;return the list of printers EndFunc Func GetDefaultPrinter() Local $szDefPrinterName Local $Size $namesize = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($namesize)) $pname = DllStructCreate("char[" & DllStructGetData($namesize, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($pname), "ptr", DllStructGetPtr($namesize)) Return DllStructGetData($pname, 1);msgbox(0,dllstructgetdata($namesize,1),DllStructGetData($pname,1)) EndFunc;==>GetDefaultPrinter1 Func PrinterSetAsDefault($PrinterName) Local $result, $strComputer, $colEvents, $np If GetDefaultPrinter() = $PrinterName Then Return 1 $result = 0 $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents If $objPrinter.DeviceID = $PrinterName Then $objPrinter.SetDefaultPrinter() $result = 1 EndIf Next If $result Then GUICtrlSetData($IPCurrentDefault,$currentPrinter) EndIf Return $result EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 (edited) can you explain how the function GetPrinterList works? i dont get how to make something so the results of the function can be selected to set what printer i want printed Edited July 20, 2008 by Golbez Link to comment Share on other sites More sharing options...
martin Posted July 20, 2008 Share Posted July 20, 2008 can you explain how the function GetPrinterList works?It uses WMI. See here.i dont get how to make something so the results of the function can be selected to set what printer i want printedThe function GetPrinterList returns a string containing all the printers separated by the '|' character. You can put that straight into a combox for example. So you could have a little gui with a combo box. Load the combo with the printer list, select the printer in the combo , press a button to start printing.But if you know the name of the printer you want to use, as shown in printers and faxes from control panel then just use that name for the printer. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 expandcollapse popup#Include <File.au3> #include <GUIConstants.au3> Global $objWMIService, $IPCurrentDefault, $currentPrinter, $printer, $PrinterName, $result $Form1 = GUICreate("Printer Setup", 306, 50, 193, 115) $Button1 = GUICtrlCreateButton("Print", 200, 8, 97, 33, 0) $Combo1 = GUICtrlCreateCombo("Select Printer", 8, 16, 185, 25) GUISetState(@SW_SHOW) GetPrinterList() While 1 $Msg = GUIGetMsg() If $Msg = $Button1 Then test() If $Msg = $GUI_EVENT_CLOSE Then Exit WEnd Func test() GUICtrlSetData($Combo1, $result) MsgBox(1, "The ComboBox Results", GUICtrlRead($Combo1)) EndFunc Func Print() $printfile = FileOpen(@ScriptDir & "\print.txt", 2) FileWriteLine($printfile, "TESTING!!!" & @CRLF) FileClose($printfile) $defaultPrinter = GetDefaultPrinter() ConsoleWrite($defaultprinter & @CRLF) $printer = $defaultprinter;<---------------------------set the printer here PrinterSetAsDefault($printer);Set whatever printer you want ConsoleWrite("Result of _FilePrint is " & _FilePrint(@ScriptDir & "\print.txt") & @CRLF) PrinterSetAsDefault($defaultPrinter);set back the original printer if you want to/need to EndFunc Func GetPrinterList() Local $result, $strComputer, $colEvents, $np,$result $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents $result &= $objPrinter.DeviceID & '|' Next $Result = StringLeft($result,StringLen($result) - 1) Return $result;return the list of printers EndFunc Func GetDefaultPrinter() Local $szDefPrinterName Local $Size $namesize = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($namesize)) $pname = DllStructCreate("char[" & DllStructGetData($namesize, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($pname), "ptr", DllStructGetPtr($namesize)) Return DllStructGetData($pname, 1);msgbox(0,dllstructgetdata($namesize,1),DllStructGetData($pname,1)) EndFunc;==>GetDefaultPrinter1 Func PrinterSetAsDefault($PrinterName) Local $result, $strComputer, $colEvents, $np If GetDefaultPrinter() = $PrinterName Then Return 1 $result = 0 $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents If $objPrinter.DeviceID = $PrinterName Then $objPrinter.SetDefaultPrinter() $result = 1 EndIf Next If $result Then GUICtrlSetData($IPCurrentDefault,$currentPrinter) EndIf Return $result EndFunc how do i put them into the combobox XD Link to comment Share on other sites More sharing options...
BrettF Posted July 20, 2008 Share Posted July 20, 2008 Oh My God.... expandcollapse popup#Include <File.au3> #include <GUIConstants.au3> Global $objWMIService, $IPCurrentDefault, $currentPrinter, $printer, $PrinterName, $result $Form1 = GUICreate("Printer Setup", 306, 50, 193, 115) $Button1 = GUICtrlCreateButton("Print", 200, 8, 97, 33, 0) $Combo1 = GUICtrlCreateCombo("Select Printer", 8, 16, 185, 25) GUISetState(@SW_SHOW) $result = GetPrinterList() GUICtrlSetData($Combo1, $result) While 1 $Msg = GUIGetMsg() If $Msg = $Button1 Then test() If $Msg = $GUI_EVENT_CLOSE Then Exit WEnd Func test() MsgBox(1, "The ComboBox Results", GUICtrlRead($Combo1)) EndFunc Func Print() $printfile = FileOpen(@ScriptDir & "\print.txt", 2) FileWriteLine($printfile, "TESTING!!!" & @CRLF) FileClose($printfile) $defaultPrinter = GetDefaultPrinter() ConsoleWrite($defaultprinter & @CRLF) $printer = $defaultprinter;<---------------------------set the printer here PrinterSetAsDefault($printer);Set whatever printer you want ConsoleWrite("Result of _FilePrint is " & _FilePrint(@ScriptDir & "\print.txt") & @CRLF) PrinterSetAsDefault($defaultPrinter);set back the original printer if you want to/need to EndFunc Func GetPrinterList() Local $result, $strComputer, $colEvents, $np,$result $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents $result &= $objPrinter.DeviceID & '|' Next $Result = StringLeft($result,StringLen($result) - 1) Return $result;return the list of printers EndFunc Func GetDefaultPrinter() Local $szDefPrinterName Local $Size $namesize = DllStructCreate("dword") DllCall("winspool.drv", "int", "GetDefaultPrinter", "str", '', "ptr", DllStructGetPtr($namesize)) $pname = DllStructCreate("char[" & DllStructGetData($namesize, 1) & "]") DllCall("winspool.drv", "int", "GetDefaultPrinter", "ptr", DllStructGetPtr($pname), "ptr", DllStructGetPtr($namesize)) Return DllStructGetData($pname, 1);msgbox(0,dllstructgetdata($namesize,1),DllStructGetData($pname,1)) EndFunc;==>GetDefaultPrinter1 Func PrinterSetAsDefault($PrinterName) Local $result, $strComputer, $colEvents, $np If GetDefaultPrinter() = $PrinterName Then Return 1 $result = 0 $strComputer = "." If $objWMIService = 0 Then $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colEvents = $objWMIService.ExecQuery _ (StringFormat('Select * From Win32_Printer')); Where DeviceID = "%s"', $PrinterName));TRUE $np = 0 For $objPrinter in $colEvents If $objPrinter.DeviceID = $PrinterName Then $objPrinter.SetDefaultPrinter() $result = 1 EndIf Next If $result Then GUICtrlSetData($IPCurrentDefault,$currentPrinter) EndIf Return $result EndFunc Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Golbez Posted July 20, 2008 Author Share Posted July 20, 2008 sorry Bert im retarted Link to comment Share on other sites More sharing options...
BrettF Posted July 21, 2008 Share Posted July 21, 2008 (edited) sorry Bert im retartedSorry man... Didn't intend to be so derogatory towards you. It was a bit early morning for me today muttley Edited July 21, 2008 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Golbez Posted July 21, 2008 Author Share Posted July 21, 2008 it was very very early for me.. like 3 am 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