Phil Chapman
asked on
Access Denied using ShellExecute(
When using ShellExecute with some LNK Files as error 5 ( Access Denied ) error is returned. ( see example below )
However you can run the line below by clicking on
Start-Run and pasting C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2003.lnk
Any help in getting this issue resolved will be appreciated.
Example:
FileName = "C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2003.lnk"
iRet = ShellExecute(GetDesktopWin dow, "open", FileName, vbNullString, vbNullString, vbNormalFocus)
If lRet = 5 Then
MsgBox "Access Denied" & vbCrLf & "Try pointing directely to the program EXE", , ""
End If
However you can run the line below by clicking on
Start-Run and pasting C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2003.lnk
Any help in getting this issue resolved will be appreciated.
Example:
FileName = "C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2003.lnk"
iRet = ShellExecute(GetDesktopWin
If lRet = 5 Then
MsgBox "Access Denied" & vbCrLf & "Try pointing directely to the program EXE", , ""
End If
Is there a reason you don't want to use WshShell.run or WshShell.execute?
Also, think that if you are going to be running a command, then it's best to point directly to the winword.exe (as your code mentions) so that you are not dependent on shortcuts that may or may not exist.
ASKER
What is the synax for using WshShell in vb6?
I'm getting a list of the program from
C:\Documents and Settings\All Users\Start Menu\Programs
The program is often referrenced to throught a link file like.
C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2003.lnk
I'm getting a list of the program from
C:\Documents and Settings\All Users\Start Menu\Programs
The program is often referrenced to throught a link file like.
C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2003.lnk
Sorry... I thought you were doing it in VBScript.
I would point to the .exe file. Typically located at
c:\program Files\microsoft office\OFFICE11\winword.EX E
I would point to the .exe file. Typically located at
c:\program Files\microsoft office\OFFICE11\winword.EX
ASKER
Pointing to the exe works fine. But I will have not way of knowing what programs the user has. Using the LNK files in VB works fine for some programs. and if you run the line form the
Start-Run prompt
All the LNK files work.
What I need to do is find out why all the LNK filds do not work in VB and work out a fix.
Start-Run prompt
All the LNK files work.
What I need to do is find out why all the LNK filds do not work in VB and work out a fix.
I can't say for certain why it's not working for you but you can try my example below it might fix the problem. Only other thing I can think of is permission access or a corrupted association of the .lnk file itself.
Option Explicit
Private Const COINIT_APARTMENTTHREADED As Long = &H2
Private Const COINIT_DISABLE_OLE1DDE As Long = &H4
Private Declare Function CoInitializeEx Lib "OLE32.DLL" ( _
ByRef pvReserved As Long, _
ByVal dwCoInit As Long) As Long
Private Declare Function ShellExecuteA Lib "shell32.dll" ( _
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 ShellIt(ByVal strPath As String) As Long
Call CoInitializeEx(0, COINIT_APARTMENTTHREADED Or COINIT_DISABLE_OLE1DDE)
ShellIt = ShellExecuteA(0, "open", strPath, vbNullString, vbNullString, 1)
End Function
Private Sub Command1_Click()
Debug.Print ShellIt("C:\Documents and Settings\Admin\Start Menu\Programs\Accessories\Tour Windows XP.lnk")
End Sub
ASKER
I tried the code above but ShellIt returned a status of 5 and the program did not start.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fantastic Work, I was about to give up on it.