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