PrinterInfo with Powershell

Post Reply
User avatar
Otto
Posts: 6378
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

PrinterInfo with Powershell

Post by Otto »

Best regards,
Otto

Code: Select all | Expand


 #include "fivewin.ch"

function main
     CreateAndRunPrinterScript() 
     CreateAndRunPrinterInfoScript()
return nil

//----------------------------------------------------------------------------//
FUNCTION CreateAndRunPrinterScript()
   LOCAL cScript, cOutputFile := ".\psfiles\get_printers.ps1"
   LOCAL cResultFile := ".\psfiles\printers_output.txt"
    LOCAL aPrinters := ""
    
   // PowerShell-Befehle als Text zusammenstellen
   cScript := '$printers = Get-ChildItem -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Print\Printers"' + CRLF
   cScript += '$output = @()' + CRLF
   cScript += 'foreach ($printer in $printers) {' + CRLF
   cScript += '    $printerName = $printer.PSChildName' + CRLF
   cScript += '    $output += $printerName' + CRLF
   cScript += '}' + CRLF
   cScript += '$output | Out-File -FilePath "' + cResultFile + '" -Encoding utf8' + CRLF

   // PowerShell-Skript in eine Datei schreiben
   MEMOWRIT(cOutputFile, cScript)

   // PowerShell-Skript ausführen
   WAITRUN("powershell.exe -ExecutionPolicy Bypass -File " + cOutputFile)

   // Ergebnis anzeigen
   IF FILE(cResultFile)
      aPrinters := MEMOREAD(cResultFile)
    msgInfo( aPrinters )
    
   ELSE
      ? "Keine Ausgabe gefunden."
   ENDIF

   RETURN NIL
   
   
   
   
   FUNCTION CreateAndRunPrinterInfoScript()
   LOCAL cScript, cOutputFile := ".\psfiles\get_printer_info.ps1"
   LOCAL cResultFile := ".\psfiles\printer_info_output.csv"

   // PowerShell-Skript zusammenstellen
   cScript := 'Get-Printer | Select-Object Name, DriverName, PortName, ShareName, PrinterStatus, Default | ' + ;
              'Export-Csv -Path "' + cResultFile + '" -NoTypeInformation -Encoding UTF8' + CRLF

   // PowerShell-Skript in eine Datei schreiben
   MEMOWRIT(cOutputFile, cScript)

   // PowerShell-Skript ausführen
   WAITRUN("powershell.exe -ExecutionPolicy Bypass -File " + cOutputFile)

   // Ergebnis anzeigen
   IF FILE(cResultFile)
     msginfo( MEMOREAD(cResultFile) )
     
   ELSE
      ? "Keine Druckerinformationen gefunden."
   ENDIF

   RETURN NIL

   

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42252
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: PrinterInfo with Powershell

Post by Antonio Linares »

Dear Otto,

Many thanks for sharing it :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
karinha
Posts: 7884
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Contact:

Re: PrinterInfo with Powershell

Post by karinha »

Mister Otto,explain, pls:

Code: Select all | Expand

   LOCAL cScript, cOutputFile := ".\psfiles\get_printers.ps1"
   LOCAL cResultFile := ".\psfiles\printers_output.txt"

   LOCAL cScript, cOutputFile := ".\psfiles\get_printer_info.ps1"
   LOCAL cResultFile := ".\psfiles\printer_info_output.csv"
 
???????????

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Otto
Posts: 6378
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: PrinterInfo with Powershell

Post by Otto »

Hello João,
I use ps1 files for many tasks, especially for installing servers, and have automated many tasks with them.
You need to create the directory. You could use c:\temp, for example.
Best regards,
Otto

c:\fwh\samples\psfiles\
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Post Reply