vbscript running multiple Powershell commands


  • I have a 500 line vbscript I wrote years ago that now won't work on Windows 7. The reason is vbscript can't perform a File Open/Browse in vbscript in Windows 7. (I've tried all the suggestions I've found on the net but none of them work except for the Word method.) I figured it was a good time to start learning Powershell and started looking at running a Powershell mini script to do the file open for me then return the selected file back to the vbs script. I've got the Powershell script and it works fine. (Thanks, Scripting Guys!) Granted this process isn't elegant but I just want to get the script working and I'll start converting it over to Powershell when I learn more.

    One twist. I don't want to call another script. I want to send all the Powershell commands at once. The problem I'm seeing is Powershell is reporting an error that is is missing a ")". The only changes I"ve made to the Powershell commands is to replace the double quotes with two double quotes so they are passed through to the Powershell command. Here's what I've got:

    Set objWSShell = CreateObject("Wscript.Shell")
    psCommand = "powershell -noexit -command {[System.Reflection.Assembly]::LoadWithPartialName("""") | Out-Null ; $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog ; $OpenFileDialog.initialDirectory = ""c:\temp"" ; $OpenFileDialog.filter = ""All files (*.*)| *.*"" ; $OpenFileDialog.ShowDialog() | Out-Null ; $OpenFileDialog.filename}"

    Path = objWSShell.Run(psCommand,,true)

    I put the -noexit command in there so I could see the error.

    Here's what Powershell reports:
    Missing ')' in method call.
    At line:1 char:52
    + {[System.Reflection.Assembly]::LoadWithPartialName( <<<<
    ) | Out-Null ; $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
     ; $OpenFileDialog.initialDirectory = c:\temp ; $OpenFileDialog.filte
    r = All files (*.*)| *.* ; $OpenFileDialog.ShowDialog() | Out-Null ; $OpenFileD
        + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], Paren
        + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

    Anyone attempted this? Any ideas?

    Monday, September 06, 2010 1:39 AM


  • I have not tried to do what you are attempting. However, if you are sure you have not mangled the code (that worked previously) then you need to add another set of quotation marks. What is happening is that the first quote escapes your quotation mark, the second one is seen as closing the one you added to the beginning of the string.

    You can also try using the backtick (`) to escape a quotation mark to make things easier to read.

    Wednesday, October 20, 2010 7:55 PM