Solved

Using ShellExecute to Open Explorer from VB - not working in Windows XP

Posted on 2004-08-29
6
1,138 Views
Last Modified: 2008-01-09
I have a program which I wrote and tested some time ago on all operating system except WinNT, Win2000 and Win XP. However, I have just started using it on Win XP and have come across a problem. The program uses the ShellExecute API function to open an Explorer window at a particular folder, however, this does not work in Windows XP!

My code is as follows:

URL = MessageFilesLocation
ingReturn = ShellExecute(fMainForm.hWnd, vbNullString, URL, vbNullString, "c:\", SW_SHOWNORMAL)

where MessageFilesLocation is the full path to the folder containing the required files. In all systems tested previously this worked perfectly, but Windows XP just sits there and looks at you without doing anything! I would appreciate any suggestions as to how to get this to work in XP/

Thanks.
0
Comment
Question by:cbitservices
  • 3
6 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 63 total points
Comment Utility
Try this:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function StartDoc(ByVal FileName As String, Optional CommandLine As String = "") As Long
    StartDoc = ShellExecute(0&, "Open", FileName, CommandLine, vbNullString, 1)
End Function

try like:

startDoc URL

* Tested working on WinXP Pro Service Pack 1

cheers
0
 
LVL 3

Assisted Solution

by:realrael
realrael earned 62 total points
Comment Utility

using the Shell function might be a more general way of implementing it on any windows platform. less complex too. - rael

error = Shell("explorer c:\temp", vbNormalFocus)
0
 
LVL 1

Author Comment

by:cbitservices
Comment Utility
No. I have tried both suggestions. I should emphasise again that I am trying to open a FOLDER in Explorer, not find or open a file. If I specify a filename it works fine and opens the file and if I specify an Internet URLit opens Internet Explorer at that website. In previous versions of word just providing a path to a folder to the ShellExecute function causes Explorer to open up at the specified folder, but this doesn't hapen with XP. Using Shell just generates an error message that the "File Cannot be found"!, whilst ShellExecute seems to do absolutely nothing.

ryancys; you say you have tested your solution; but did you test it with a the full path to a folder, not including a filename? If so, then I don't understand why it doesn't work here! Thanks.
0
 
LVL 1

Author Comment

by:cbitservices
Comment Utility
OK. I found the problem! It was just an error in the path being passed to the function! Thanks anyway guys.
0
 
LVL 1

Author Comment

by:cbitservices
Comment Utility
ryancys - your answer was technically perfect, even though my code was also perfect and working correctly once the correct path was passed to it! It turned out that the reason it wasn't opening the folder was the fact that the folder didn't exist!!! The program was assuming that the folder had been created, but on this one instance, due to rare and particular circumstances, it hadn't! The fact that the Shell function produced an error message, which was actually quite accurate, means that realrael's contribution must also be considered useful; even though I didn't pick up on it at the time! I quickly accepted ryancys's comment as the answer just to close the question, but on reflection I feel you both deserve to share the points. i will therefore request that the points are split equally between you; I hope you both agree that this is the fairest solution.Thanks again for your prompt replies and your considered thoughts.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 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

11 Experts available now in Live!

Get 1:1 Help Now