Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Replacement for 'UserAccounts.CommonDialog'

Posted on 2014-03-04
3
Medium Priority
?
858 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 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 35

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

721 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