XP SP2 and ShellExecuteEx
I'm having the MOST fun ever with Win32 API calls in XP SP2 at the moment.
I'm trying to launch documents when the responsible executable (eg Word) is not in a known location.
This is the same as double clicking on a document.
For this example, I am using a TEXT document, in a path with no spaces, less than 25 characters long.
I can OPEN, and SAVE the document
I have READ & EXECUTE permissions as well as all the usual permissions.
But this fails with ERROR_ACCESS_DENIED
Dim SEI As SHELLEXECUTEINFO
Dim r As Long
With SEI
'Set the structure's size
.cbSize = Len(SEI)
'Seet the mask
.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI 'Or SEE_MASK_NOZONECHECKS
'Set the owner window
.hWnd = 0
'Show the properties
If (Len(params) < 1) Then
.lpVerb = "open"
Else
.lpVerb = params
End If
'Set the filename
.lpFile = DocumentPath
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
.lpClass = vbNullChar
.hProcess = 0
End With
ShellExecuteEx SEI
OpenDocument = SEI.hInstApp
On the other hand, this works, but opens windows, etc which can be messy.
OpenDocument = ShellExecute(Application.hWndAccessApp, params, DocumentPath, vbNullChar, vbNullChar, windowState)
Under XP SP1 ShellExecuteEx worked. Under SP2 it does not. But nowhere can I find any explanation, mention or work around.
Huh.
Turns out the struct definition I was using belonged to a old version of the API. It was missing hkeyClass As Long.