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

就这么简单!:) 感谢您的指导,Kayasax!

powerShell -sta -file PowerTools.ps1
于 2012-11-29T13:32:17.490 回答
1

https://technet.microsoft.com/en-us/library/hh847736.aspx says that -file must be last in the in the list of options because everything after the file name is interpreted as parameters to the file. That is why it works when -sta is listed before -file, but does not work after -file.

于 2016-03-02T17:00:14.903 回答