windowsvbscripthta

How to browse for file (Win7/64bits)


I need to quickly write a simple GUI over a command line application. Two steps are required:

  1. Specify an input file path,
  2. Specify an output file path (non existing)

I found out a previous post, however trying to get the above (1) to work seems like an insane task.

Indeed BrowseForFolder seems to only work in some weird cases, you can use BIF_BROWSEINCLUDEFILES for only *.pdf and/or *.txt (trial and errors). I can get an error if I select a *.dll and/or a *.jpg (don't ask).

So instead, I gave up this approach and followed another one, in this case (objIE.Document.all.FileSelect), only the name of the selected file is returned the path seems to be always set to "c:/fakepath" for some reason. So again I am missing the full path to be able to pass that to the command line app.

Is there any sane way (<10 lines of codes) to get (1) and (2) working on Win7/64bits (VBS, HTA...)?


Solution

  • Don't know if people are still interested in the BrowseForFolder file selection issue, but here's what I've found. I had the same issue selecting files with BrowseForFolder using &H4000 / BIF_BROWSEINCLUDEFILES. I could get a return with .docx but not .doc files and as you say .pdf files. For me .txt wouldn't return anything, as didn't WMI Backup .rec files that I needed for a script I'm writing, resulting in this error information:-

    Error: Unspecified error
    Code: 80004005
    Source: (null)
    

    After looking at other solutions I came back to this one as my preferred choice, plus it was doing my head in that it didn't want to work. So at the bitter end it seems to be this easy. To get my .rec files recognized I add this to the registry:-

    [HKEY_CLASSES_ROOT\.rec]
    @="WMI.Backup"
    
    [HKEY_CLASSES_ROOT\WMI.Backup]
    @="WMI Backup"
    "BrowseInPlace"="1"
    

    To get .txt files recognized I add this to the registry:-

    [HKEY_CLASSES_ROOT\txtfile]
    "BrowseInPlace"="1"
    

    So "BrowseInPlace"="1" seems to be the nugget.

    Seems so unbelievably easy that I'm sure this solution is out there somewhere but I never came across it so thought I'd put it online.

    I would be interested to find that it works for others as I fear that this issue may of sent me mad, still can't believe it seems to work. Hope this helps.