Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(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
I have try this code to open bookmarks, programs, images, ... and it works fine but when I try to open a shortcut it fails (Nothing appears).
----------------------------
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (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
Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
Dim i As Long
i = ShellExecute(hwnd, "open", "D:\shortcut.lnk", "", "", SW_SHOWNORMAL)
End
End Sub
------------------------
Um...I think I can see what is happening here...are you renaming the shortcuts? And, if so, are you manually adding ".lnk" to the name? I ask because shortcuts already have .lnk as their file extension, but this is hidden from you in the GUI (even if you have chosen not to hide file extensions via Folder Options).
In other words, when you rename a shortcut to "shortcut.lnk" the real filename is "shortcut.lnk.lnk" (and it is this real filename that needs to be passed to the ShellExec function
Ok, if you say so. I'd still argue that the symptoms your are experiencing and explaining are 100% compliant with the filename being wrong.
How are you creating the shortcut? Normally, if I was creating (via the GUI) a shortcut to Notepad, that shortcut would be (in the GUI) "Shortcut to Notepad", and not "Shortcut". So, if you are not renaming anything, how are you getting shortcuts called "Shortcut"?
I have renamed the shortcut, but I was meaning I haven't renamed the extension or I haven't added an extra extension. After all, if I see a file called shortcut.lnk in a DOS box. That's the filename I ought to use calling to ShellExecute.
I ask because:
a) You said you hadnt renamed the shortcut, but then agreed you had done but didn't think it important enough to originally admit
b) the technique outlined by LPlates is one I use regularly myself (along with two other techniques) and it works fine here on W98, W2K and XP. SO there has got to be something else going on...
I am not trying to confuse you, or tryng you waste your valuable time. I am asking help because I have a problem. Apparently the problem (or the solution) is very simple but I have, at this moment, a piece of code that doesn't work as is expected.
I didn't want to hide that I had renamed the shortcut. Simply, I knew that the GUI wasn't showing the real name of the file (because of that I said: 'I can see it in a DOS box').
I have created a new shortcut to NOTEPAD.EXE. I have copied the filename showed in a DOS box ('Acceso directo a NOTEPAD.EXE.lnk') and pasted in my project, replacing the 'Shortcut.lnk' used before. And I have the same result. A Msgbox Dialog showing 'Acceso directo a NOTEPAD.EXE.lnk' and nothing else.
S'OK, I appreciate that. I was just trying to get more info, since the code as provided by LPlates should work, and does work here on several machines and with several different Windows OS. The conclusion has to be that there is something different about your setup, and we need to try and find out what it is.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.