I have a VB6 application which opens files with their associated application using:
ShellExecute(0, "open", filename, params, vbNullString, vbNormalFocus)
This works perfectly.
Now I got a customer (running XP with Adobe Reader) who can't open any PDF file using the above command. But the same file is being opened without any problems when double clicking it from Windows Explorer. I also tested the filename/-path combination on my machine to exclude those kind of problems.
I'm searching for any hints on what I could check to make sure ShellExecute
is working. Or what can cause ShellExecute to fail this way?
How to: This is caused by the Avast antivirus, and can be solved by turning off Avast for the time of install. Please note that creating an exception for the program in Avast does not solve the install issue.
Step 1: Right-click on the application that is triggering the error, and select Properties. Step 2: Select the Compatibility tab and check Run this program as administrator under the Settings section. Click Apply. Step 3: Run the application again and see if the “Shellexecuteex Failed” error is fixed.
To use ShellExecute or ShellExecuteEx, your application must specify the file or folder object that is to be acted on, and a verb that specifies the operation. For ShellExecute, assign these values to the appropriate parameters. For ShellExecuteEx, fill in the appropriate members of a SHELLEXECUTEINFO structure.
Further to Thomas's answer, here's some VB6 constants for possible return values of ShellExecute, with possible explanations (I think I originally took these from the MSDN page, return value section). A return value of 32 or less means the call failed. The specific value returned indicates what went wrong.
Const ERROR_BAD_FORMAT = 11&
Const ERROR_FILE_NOT_FOUND = 2&
Const ERROR_PATH_NOT_FOUND = 3& ' The specified path was not found. '
Const SE_ERR_ACCESSDENIED = 5 ' The operating system denied access to the specified file. '
Const SE_ERR_ASSOCINCOMPLETE = 27 ' The file name association is incomplete or invalid. '
Const SE_ERR_DDEBUSY = 30 ' The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed. '
Const SE_ERR_DDEFAIL = 29 ' The DDE transaction failed. '
Const SE_ERR_DDETIMEOUT = 28 ' The DDE transaction could not be completed because the request timed out. '
Const SE_ERR_DLLNOTFOUND = 32 ' The specified dynamic-link library (DLL) was not found. '
Const SE_ERR_FNF = 2 ' The specified file was not found. '
Const SE_ERR_NOASSOC = 31 ' There is no application associated with the given file name extension. '
Const SE_ERR_OOM = 8 ' out of memory '
Const SE_ERR_PNF = 3 ' path not found '
Const SE_ERR_SHARE = 26 ' A sharing violation occurred. '
What's the return value of ShellExecute? If it's 0x0000001f (== 31, meaning SE_ERR_NOASSOC
), than according to shellapi.h "There is no application associated with
the given file name extension.", which means that somehow the registration of the .pdf file extension got lost. Reinstalling Adobe Reader might help.
You have "open" as the verb, don't do that, use vbNullString as the verb ("Open" means the open verb, NULL means the default verb (If the user has not set a specific default, the default is open, if there is no open verb for that filetype, ShellExecute uses the first verb it finds))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With