ShellExecuteEx and PDF files (1 Viewer)

ByteMyzer

AWF VIP
Local time
Today, 00:02
Joined
May 3, 2004
Messages
1,409
For my company, I wrote an application that includes a function called FileExecute, which takes file path parameter lpFile, calls the open command with the ShellExecuteEx function and returns the Process handle:

Ex: ?FileExecute("C:\MyFolder\MyFile.txt")

...opens up the file with the associated program (NOTEPAD.EXE) and returns the Process handle. My program uses this information to terminate the running process when the main program closes.


There is ONE user's machine which has a problem with this program when attempting to open PDF files (not other file types). When the program calls the FileExecute function, his machine returns:

Run-Time Error: 5 - Invalid procedure call or argument


This user's machine was upgraded from Adobe Acrobat Reader to Adobe Acrobat Standard 8.0, and the problem manifests itself on his machine, ONLY on his Windows Network Login. When I or any other User logs onto his machine, it runs just fine.

I suspect the problem lies somewhere in his HKEY_CURRENT_USER registry setting, but am not sure how to address it. Has anyone else encountered this problem, or can anyone recommend a solution?


Below is the code, for reference:
Code:
Option Explicit

Private Declare Function ShellExecuteEx Lib "shell32.dll" ( _
    lpExecInfo As SHELLEXECUTEINFO) _
    As Long

Private Type SHELLEXECUTEINFO
    cbSize As Long
    fMask As Long
    hWnd As Long
    lpVerb As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShow As Long
    hInstApp As Long
    lpIDList As Long
    lpClass As String
    hkeyClass As Long
    dwHotKey As Long
    hIcon As Long
    hProcess As Long
End Type

Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_INVOKEIDLIST = &HC
Private Const SEE_MASK_FLAG_NO_UI = &H400

Private Const SW_NORMAL = 1

Public Function FileExecute(ByVal lpFile As String) As Long

Dim lpExecInfo As SHELLEXECUTEINFO

With lpExecInfo
    .cbSize = Len(lpExecInfo)
    .fMask = SEE_MASK_NOCLOSEPROCESS
    .lpFile = lpFile
    .lpVerb = "open"
    .nShow = SW_NORMAL
    .hWnd = Form1.hWnd
End With

ShellExecuteEx lpExecInfo

FileExecute = lpExecInfo.hProcess

End Function
 

DCrake

Remembered
Local time
Today, 08:02
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

From what you are stating there is nothing wrong with your coding, as it works on that pc with a diferent user logged in. The source of the error lies with the users profile. I suggest you delete the user profile copy another users profile to add a new user (the one you just deleted).

The newly created user should now have the same rights and privilages as the source user.

CodeMaster::cool:
 

ByteMyzer

AWF VIP
Local time
Today, 00:02
Joined
May 3, 2004
Messages
1,409
Deleting and re-creating the user's profile did the trick. Thanks a million!
 

DCrake

Remembered
Local time
Today, 08:02
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

Like I say the simplest apporach is usually the best. Glad to be of help.:)
 

Users who are viewing this thread

Top Bottom