Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
powershell从作业中执行visual basic代码_Powershell_Jobs - Fatal编程技术网

powershell从作业中执行visual basic代码

powershell从作业中执行visual basic代码,powershell,jobs,Powershell,Jobs,我试图将下面的代码作为作业启动,但我认为我没有在作业中正确初始化程序集 下面的代码块是我希望在powershell的作业中执行的代码 [void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") [Microsoft.VisualBasic.Interaction]::MsgBox("DART Report completed.", "okon

我试图将下面的代码作为作业启动,但我认为我没有在作业中正确初始化程序集

下面的代码块是我希望在powershell的作业中执行的代码

[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") 
[Microsoft.VisualBasic.Interaction]::MsgBox("DART Report completed.", "okonly,MsgBoxSetForeground,Information,DefaultButton2", "Report")
这是我试图执行一个模拟代码块,当它完成时,它似乎给我一个powershell弹出窗口,不像上面的代码块

$script:job = Start-Job -ScriptBlock {param($HostName, $username)
Add-Type -AssemblyName System.Windows.Forms, System.Reflection.Assembly, Microsoft.VisualBasic
[void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") 
[Microsoft.VisualBasic.Interaction]::MsgBox("Report completed.", "okonly + vbExclamation,MsgBoxSetForeground,Information,DefaultButton2", "DART Report")} -ArgumentList ($HostName, $username)

任何帮助都将不胜感激,谢谢

您的脚本需要一些更正:

  • 您应该添加System.Reflection,而不是System.Reflection.Assembly
  • MsgBox的第二个参数应该是以引号分隔的vb选项,对于vb对话框,您不应该混合使用
    信息
    感叹号
  • 以下是更正后的脚本:

    $script:job = Start-Job -ScriptBlock {param($HostName, $username)
    Add-Type -AssemblyName System.Windows.Forms, System.Reflection, Microsoft.VisualBasic
    [void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
    [Microsoft.VisualBasic.Interaction]::MsgBox("Report completed.", "okonly,MsgBoxSetForeground,Exclamation,DefaultButton2", "DART Report")} -ArgumentList  ($HostName, $username)
    
    它应该会提示您一个正确的感叹号对话框。如果您希望在powershell的前两行中出现类似的对话框,则必须将
    感叹号
    替换为
    信息

    编辑:正如@mklement0在注释中所述,
    [void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.VisualBasic”)
    在脚本中不是必需的。对于类型
    System.Reflection
    System.Windows.Forms
    ,在逻辑上也是相同的,即使您以后想使用反射

    以下是修改后的相应脚本:

    $script:job = Start-Job -ScriptBlock {param($HostName, $username)
    Add-Type -AssemblyName Microsoft.VisualBasic
    [Microsoft.VisualBasic.Interaction]::MsgBox("Report completed.", "okonly,MsgBoxSetForeground,Exclamation,DefaultButton2", "DART Report")} -ArgumentList  ($HostName, $username)
    

    优点很好,但值得一提的是,
    [void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.VisualBasic”)
    是不需要的,而
    添加类型-AssemblyName Microsoft.VisualBasic
    是使
    [Microsoft.VisualBasic.Interaction]调用工作的唯一先决条件::MsgBox(…)
    (甚至在PultSeore(Core)7 +中不需要这样做。也请考虑删除命令继续提示(<代码> > <代码>)。从你的答案,以便让其他人简单地复制粘贴你的代码,以运行它。谢谢你们,这完全清除了我的问题。我终于可以有这个工作通知我,并有它弹出窗口,让我可以看到它。非常感谢!!!!!