使用PowerShell在VBScript中打开文件对话框

使用PowerShell在VBScript中打开文件对话框,powershell,command-line,vbscript,dialog,command-prompt,Powershell,Command Line,Vbscript,Dialog,Command Prompt,我想从VBScript显示一个文件对话框,我想使用PowerShell 如何将此PowerShell代码与CreateObject(“WScript.Shell”).Exec()一起使用,以使用StdOut属性获取PowerShell输出 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") $OpenFileDialog = New-Object System.Windows.Forms.OpenF

我想从VBScript显示一个文件对话框,我想使用PowerShell

如何将此PowerShell代码与
CreateObject(“WScript.Shell”).Exec()一起使用,以使用
StdOut
属性获取PowerShell输出

[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = "C:\"
$OpenFileDialog.filter = "|*.*"
$OpenFileDialog.ShowDialog()
$OpenFileDialog.filename

嗯,我想我做到了。以前从未见过这种方法

我正在为Windows 8编写脚本,但其他方法不可用,或者不可用

Function OpenFileDialog(sDir, sFilter, sTitle)
    With Createobject("Scripting.FileSystemObject")

        If .FileExists("OUTPUT") Then .DeleteFile("OUTPUT")

        CreateObject("WScript.Shell").Run _
            "powershell.exe -command ""& {"& _
                "[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null;"& _
                "$o = New-Object System.Windows.Forms.OpenFileDialog;"& _
                "$o.InitialDirectory = '"& sDir &"';"& _
                "$o.Filter = '"& sFilter &"';"& _
                "$o.Title = '"& sTitle &"';"& _
                "$o.ShowDialog() | Out-Null;"& _
                "$o.filename > OUTPUT"& _
            "}""",0

        Do
            WScript.Sleep 100
        Loop While Not .FileExists("OUTPUT")

        With .OpenTextFile("OUTPUT", 1, False, -1)
            Do While .AtEndOfStream
                WScript.Sleep 100
            Loop
            OpenFileDialog = .ReadLine
        End With

        .DeleteFile("OUTPUT")

    End With
End Function    

msgbox(OpenFileDialog("D:\", "|*.*", ""))

如果您已经在用VBScript编写,为什么要通过PowerShell打开OpenFileDialog?为什么不通过VBScript打开它呢?CreateObject(“UserAccounts.CommonDialog”)用于XP,CreateObject(“MSComDlg.CommonDialog”)不在Windows 8上,这正是我需要的。如果我错了,或者你知道另一种方法,请告诉我。将不胜感激。