【发布时间】:2017-11-11 15:13:12
【问题描述】:
我有一个简单的 PowerShell 脚本,它使用 windows.forms 来使用 GUI 呈现和获取数据。 当我使用 PowerShell 运行它时它可以工作,但不能通过 CMD 工作。 这是 .ps1 示例:
[System.Windows.MessageBox]::Show('message','Step 1','YesNoCancel','Question')
执行批处理文件:
powershell "&{start-process powershell -ArgumentList ' -noprofile -file c:\temp\gui.ps1' -verb RunAs} exit $LASTEXITCODE" < NUL
我得到的错误是:找不到类型 [System.Windows.MessageBox]。 我知道 CMD 运行在不同的上下文和程序集需要加载,所以我尝试从 CMD 命令加载它,但仍然是同样的错误。
powershell "&{[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); start-process powershell -ArgumentList ' -noprofile -file c:\temp\gui.ps1' -verb RunAs} exit $LASTEXITCODE" < NUL
【问题讨论】:
标签: winforms powershell batch-file cmd