Link to home
Start Free TrialLog in
Avatar of cbitservices
cbitservicesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cbitservices

ASKER

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.
OK. I found the problem! It was just an error in the path being passed to the function! Thanks anyway guys.
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.