Sign in to follow this  
Followers 0
antmar904

Write column 1 from 2D array to file

6 posts in this topic

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)

post-75109-0-92339900-1410901108_thumb.p

Share this post


Link to post
Share on other sites



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)

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

... 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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0