3

WPKを使用して PowerShell で小さな GUI ツールを開発しました。

次の起動コマンドがあります

powershell -ExecutionPolicy Unrestricted -file PowerTools.ps1 -noexit -sta

次のエラーが表示されます。

New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require this."
At \WindowsPowerShell\Modules\WPK\GeneratedControls\PresentationFramework.ps1:34
10 char:29
+         $Object = New-Object <<<<  System.Windows.Window
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId :     ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

私のグーグルから、STAは「シングルスレッドアパートメント」を立ち上げます。powershell.exeに「-sta」フラグがあることに気付きましたが、それも役に立ちません。

私のps1ファイルの本質は次のようになります

Import-Module WPK

function get-gui()
{
      New-Window  -WindowStartupLocation CenterScreen `
       -Width 1200 -Height 200 -Show {

      New-Grid -Rows 32, 32, 32, 32 -Columns 110, 200* {
            ...
          }
        }
    }
}

get-gui

ヒントはありますか?

(私は自分の研究にかなりの時間を費やしました)

4

2 に答える 2

3

こんなに簡単!:) カヤサックスさん、ご指導ありがとうございます!

powerShell -sta -file PowerTools.ps1
于 2012-11-29T13:32:17.490 に答える