Tags: programming

Walle

VBScript: Getting a File Browse Dialog in Windows 7

If you need a file open dialog in a VBScript, you have plenty of possibilities in XP to do it quick and easy. In Windows 7, however, they don't work anymore. Google found me a few ways to get a file dialog in Windows 7, but they all had flaws like not working for all file types, or not being able to be starting in a pre-set folder, or only returning the file name, not the full path, or needing ActiveX components that I just couldn't get to work.

In the end, I found jsShell, which provides dialog windows that just do what you expect them to do and are easy to use. And even I was able to get them to work.

Of course, there're a few steps needed to enable them:
  • Download jsShell.zip (180 KB) and unpack it.
  • In order to work in 64-bit Windows, move jsShell.dll to %WINDIR%\SysWOW64 (usually %WINDIR% is C:\Windows). Do NOT use System32!
  • Register it to Windows:
    Right-click cmd.exe - Run as Administrator and type
    cd \%WINDIR%\SysWOW64 <Enter>
    regsvr32 jsShell.dll <Enter>
  • Set Windows to use the 32-bit version of WScript for .vbs files. In the registry, there should be a path HKEY_CLASSES_ROOT\VBSFile\Shell\Open\Command. The (Default) value will read something like "%SystemRoot%\System32\WScript.exe" "%1" %*. Leave the value intact but change System32 to SysWOW64. That will cause the 32-bit version of WScript.exe to handle .vbs files.


  • Once you've set it up, you can invoke a file browser dialog in VBScript like this:

    Dim objJs

    Set objJs = CreateObject("jsShell.Ops")
    myFile = objJs.OpenDlg("Select file", "txt", "C:\MyStuff")

    (See also the demo scripts coming with jsShell.zip)