Common File Dialog replacement for W7


  • Hi
    I have used the following excerpt of a script to display a file select
    box with XP and copy the selected file as part of a larger script.
    On W7, this does not work anymore. I searched the web and found that I
    am not the only one having this issue. However, I could not find a
    solution that works so far.

    With some assistance in the SBS forum we found that the CommonDialogs are no longer available starting from Vista.

    Any suggestions how to modify this script that it runs on W7 (and XP ideally)?
    ' If OK has been selected, we show a file dialog to select a file and copy the file
    Set objDialog = CreateObject("UserAccounts.CommonDialog")
    objDialog.Filter = "Eagle BOM|*.txt|All Files|*.*"
    objDialog.FilterIndex = 1
    objDialog.InitialDir = SourcePath
    Set oFS = CreateObject("Scripting.FileSystemObject")
    intResult = objDialog.ShowOpen
    If intResult = 0 Then
        Set oFile = oFS.GetFile(objDialog.FileName)
        oFile.Copy (TargetPath & "CADimport.txt")
        prompt = "BOM  " + oFile + "  wurde kopiert und bereitgestellt"
        intResult = MsgBox(prompt, 64, title)
    End If
    Thanks a lot

    Monday, June 20, 2011 12:47 PM


All replies

  • Mmm... I see what you mean.  But be patient!
    Monday, June 20, 2011 3:22 PM
  • None of the controls are available on Vista and later.  Use third party replacements or switch to PowerShell.

    Here is a simple PowerShell example.

    $dlg = new-object System.Windows.Forms.OPenFileDialog


    You can also look for one of the many HTML or HTA replacememts for use in VBScript.


    • Marked as answer by Franz Leu Tuesday, June 21, 2011 1:21 PM
    Monday, June 20, 2011 3:51 PM
  • Thanks, jrv.

    I found that file name chosen can be accessed by: $dlg.FileName

    Here is the link for more info on the FileDialog.FileName Property:

    General info about the OpenFileDialog Class:

    • Marked as answer by Franz Leu Tuesday, June 21, 2011 1:21 PM
    Monday, June 20, 2011 4:23 PM
  • Frank -

    Sorry - I should have posted a link.  Thanks.

    Monday, June 20, 2011 5:56 PM
  • OK, thank you guys.
    Seems that it really can not be done simply by modifying the current
    script. I never used PowerShell so far, so this all is kinda new for me
    and needs a lot more work than I thought.
    Thanks anyway.
    Tuesday, June 21, 2011 1:19 PM
  • Hi Franz,

    I was new to Powershell until about a month ago.  Then I watched a series of videos by Ed Wilson (THE scripting guy).  Here is a link to the series of 5 videos to get you up and running fast.

    It's called "Windows PowerShell: Learn It Now Before It's an Emergency"

    They are very well presented, and easily understandable to anyone who has scripted before.  Highly recommended.

    I was very reluctant at first, coming from a VB6/VBA/VBS background, but now I'm hooked on Powershell.  It's powerful!

    Tuesday, June 21, 2011 1:45 PM