antmar904 Posted September 16, 2014 Share Posted September 16, 2014 Hi all, I cant seem to get it working with arrays for some reason. Basically i want to list all the printers that are installed on a computer and write them to a file. I am using a print function from >HERE but i only want to write column 1 (print names) #include <Printers.au3> #include <File.au3> #include <Array.au3> $PrinterList = @ScriptDir & "\PrinterList.log" $aPrinterList = _EnumPrinterConfiguration() _FileWriteFromArray ($PrinterList, $aPrinterList) _ArrayDisplay($aPrinterList) Link to comment Share on other sites More sharing options...
JohnOne Posted September 16, 2014 Share Posted September 16, 2014 I cant seem to get it working with arrays for some reason. Did to try ... AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Gianni Posted September 16, 2014 Share Posted September 16, 2014 you could use _ArrayExtract() #include <Printers.au3> #include <File.au3> #include <Array.au3> $PrinterList = @ScriptDir & "\PrinterList.log" $aPrinterList = _EnumPrinterConfiguration() ; $aColumn1 = _ArrayExtract($aPrinterList, Default, Default, 1, 1) ; <- extract only column 1 ; _FileWriteFromArray($PrinterList, $aColumn1) _ArrayDisplay($aColumn1) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jguinch Posted September 17, 2014 Share Posted September 17, 2014 ... or use a simple loop : #include "Printers.au3" #include <Array.au3> $PrinterList = @ScriptDir & "\PrinterList.log" $aPrinterList = _EnumPrinterConfiguration() $hFile = FileOpen($PrinterList, 2) For $i = 0 To UBound($aPrinterList) - 1 FileWriteLine($hFile, $aPrinterList[$i][1]) Next FileClose($hFile) _ArrayDisplay($aPrinterList) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted September 17, 2014 Share Posted September 17, 2014 Or if the list is the only thing you need to get, use only the udf part which does this #Include <Array.au3> $res = _EnumPrinters() _ArrayDisplay($res) Func _EnumPrinters() Local $aResult[1], $i = 0, $strComputer = "." $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") $colPrinters = $objWMIService.ExecQuery ("Select Name from Win32_PrinterConfiguration", "WQL", 0x10 + 0x20) If NOT IsObj($colPrinters) Then Return 0 For $objPrinter in $colPrinters $i += 1 Redim $aResult[$i] $aResult[$i-1] = $objPrinter.Name Next Return $aResult EndFunc Link to comment Share on other sites More sharing options...
antmar904 Posted September 17, 2014 Author Share Posted September 17, 2014 you could use _ArrayExtract() #include <Printers.au3> #include <File.au3> #include <Array.au3> $PrinterList = @ScriptDir & "\PrinterList.log" $aPrinterList = _EnumPrinterConfiguration() ; $aColumn1 = _ArrayExtract($aPrinterList, Default, Default, 1, 1) ; <- extract only column 1 ; _FileWriteFromArray($PrinterList, $aColumn1) _ArrayDisplay($aColumn1) Thank you Chimp, this worked. I will try the other suggestions later on today. 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