Solved

Replacement for 'UserAccounts.CommonDialog'

Posted on 2014-03-04
3
781 Views
Last Modified: 2014-03-04
We have discovered that VB scripts written for XP using 'UserAccounts.CommonDialog' (which enables the user to browse to a file, and returns a text string containing the name of the file) do not work in Windows 7.  I have spent an inordinate amount of time researching a replacement.  What I have found is myriad solutions that get shut down by new MS security enhancements, or have limitations regarding the kind of file that one can select, or limitations relating to the return of the file name only, and not the full path.

RobSampson provided a great solution on 4/4/2013 that can be found on EE under the title "Windows 7 CommonDialog class at:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Windows_7/Q_28070742.html#a39049827

I have modified it so that it runs in our scripting environment, including allowing the user to select All Files *.*

What I cannot figure out is how to specify the starting path location for the search.  The key line is:

tempFile.WriteLine("    s = Dlg.openfiledlg(, , CStr(" & strDQ & "Microsoft Word(*.doc;*.docx)|*.doc;*.docx|Microsoft Excel(*.xls;*.xlsx)|*.xls;*.xlsx|Adobe PDF(*.pdf)|*.pdf|" & strDQ & "), CStr(" & strDQ & "Choose File" & strDQ & "))")

If I am correct, that .openfiledlg method is defined at MS page:
http://msdn.microsoft.com/en-us/library/aa769135(v=vs.85).aspx
and if that reference is correct, the second argument, which is blank in the above line of code, is the initial directory:
HRESULT openfiledlg(
    VARIANT initFile,
    VARIANT initDir,
    VARIANT filter,
    VARIANT title,
    BSTR *pathName
);
Parameters
initFile [in] VARIANT of type VT_BSTR that contains the initial file name to open.
initDir [in] VARIANT of type VT_BSTR that contains the initial directory to open.

When I look at the other arguments that Rob has successfully placed in that openfiledlg call, such as the 'title' argument, I do not recognize
his syntax:  CStr(" & strDQ & "Choose File" & strDQ & ")
which does not look like other instances I have seen:   ie. simply "c:\"

I have tried and failed testing every variation I can think of in order to set that second argument called initDir, including such things as
      "c:\data"
      CStr("c:\data")
      CStr(" & strDQ & CStr("c:\data") & strDQ & ")
      CStr(" & strDQ & CStr("c:\data\") & strDQ & ")
      CStr(" & strDQ & CStr("c:\\data") & strDQ & ")
      CStr(" & strDQ & CStr("c:\\data\\") & strDQ & ")
      CStr(" & strDQ & CStr("c:\\data") & strDQ & ")
      CStr(" & strDQ & CStr(""c:\\data"") & strDQ & ")
      CStr(" & strDQ & CStr(""c:\\data\\"") & strDQ & ")

Does anybody have any suggestions here?
0
Comment
Question by:miketonneson
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39904789
If you look a little bit lower in that thread, you will see the syntax for opening c:\temp, for ex, is:
 tempFile.WriteLine("    s = Dlg.openfiledlg(CStr(" & strDQ & "C:\Temp\*" & strDQ & "), , CStr(" & strDQ & "Microsoft Word(*.doc;*.docx)|*.doc;*.docx|Microsoft Excel(*.xls;*.xlsx)|*.xls;*.xlsx|Adobe PDF(*.pdf)|*.pdf|" & strDQ & "), CStr(" & strDQ & "Choose File" & strDQ & "))")

Open in new window


HTH,
Dan
0
 

Author Closing Comment

by:miketonneson
ID: 39904902
That works.  Thanks so much.
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39904920
Glad I could help. It's not my solution, I just read a bit further :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now