以下に示すように、PowerShell から印刷キューのリストを取得しようとしています。しかし、私は得ています
The calling thread cannot access this object because a different thread owns it
.
PowerShell が複数のスレッドをサポートできないために発生しているのでしょうか?
この問題を回避する方法はありますか?
以下に示すように、PowerShell から印刷キューのリストを取得しようとしています。しかし、私は得ています
The calling thread cannot access this object because a different thread owns it
.
PowerShell が複数のスレッドをサポートできないために発生しているのでしょうか?
この問題を回避する方法はありますか?
私が理解している限り、コードを機能させるには、PowerShell を -STA (シングル スレッド アパートメント) パラメーターで起動する必要があります。
PowerShell -STA
Add-Type -AssemblyName "system.Printing"
$f = @([system.Printing.EnumeratedPrintQueueTypes]::local, [system.Printing.EnumeratedPrintQueueTypes]::shared)
$ps = New-Object system.Printing.localprintserver
$pq = $ps.GetPrintQueues($f)