从Windows命令提示符执行PowerShell脚本
我已安装64位Windows 10的当前版本 我可以打开Windows PowerShell窗口并输入以下命令以执行我的PowerShell脚本。脚本执行时不会出错从Windows命令提示符执行PowerShell脚本,powershell,windows-10-desktop,Powershell,Windows 10 Desktop,我已安装64位Windows 10的当前版本 我可以打开Windows PowerShell窗口并输入以下命令以执行我的PowerShell脚本。脚本执行时不会出错 PS C:\Users\david\Desktop\test> ./messagebox.ps1 我想从Windows命令提示符窗口执行相同的脚本。当我输入follow命令时,我会得到显示的错误消息 C:\Users\david\Desktop\test>powershell -ExecutionPolicy Bypa
PS C:\Users\david\Desktop\test> ./messagebox.ps1
我想从Windows命令提示符窗口执行相同的脚本。当我输入follow命令时,我会得到显示的错误消息
C:\Users\david\Desktop\test>powershell -ExecutionPolicy Bypass -file messagebox.ps1
At C:\Users\david\Desktop\test\messagebox.ps1:81 char:14
+ Class Form : System.Windows.Forms.Form
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.Forms.Form].
At C:\Users\david\Desktop\test\messagebox.ps1:102 char:21
+ return [System.Windows.Forms.MessageBox]::Show($messsage, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.Forms.MessageBox].
At C:\Users\david\Desktop\test\messagebox.ps1:108 char:21
+ return [System.Windows.Forms.MessageBox]::Show($messsage, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unable to find type [System.Windows.Forms.MessageBox].
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TypeNotFound
脚本包括以下几行,我认为这些行将包括正确的程序集
$n = new-object System.Reflection.AssemblyName("System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[System.AppDomain]::CurrentDomain.Load($n) | Out-Null
您没有发布足够的代码来实际复制该问题,但这对我很有用:
Add-Type -AssemblyName System.Windows.Forms | Out-Null
[System.Windows.Forms.MessageBox]::Show("Hello World")
我假设您可以将其扩展到所需的Show()的任何版本
另请参见您没有发布足够的代码来实际再现该问题,但这对我来说是可行的:
Add-Type -AssemblyName System.Windows.Forms | Out-Null
[System.Windows.Forms.MessageBox]::Show("Hello World")
我假设您可以将其扩展到所需的Show()的任何版本
另请参见我应该包括一个示例。我没有修改我的问题,而是发布了一个新问题。对于这个问题,你的答案是正确的。你的另一个问题很有趣。学到了一些新东西我应该举个例子。我没有修改我的问题,而是发布了一个新问题。对于这个问题,你的答案是正确的。你的另一个问题很有趣。学到了一些新东西