Solved

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

Posted on 2004-08-29
6
1,147 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
[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
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 63 total points
ID: 11924939
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
ID: 11924961

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
ID: 11925047
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
ID: 11925060
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
ID: 11925069
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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