I've witnessed an interesting problem. Normally ShellExecute() API can run Windows links (.lnk files) but not the ones that have Registry links in them - something like a network connection shortcut (where the target is set to something like: {BA126AD7-2166-11D1-B1D0-00805FC1270E}). It simply returns error code 87.
I need to be able to run those links as well. Do you have any suggestions?
The behavior of this API seems to change from system to system. Now when I'm at home it doesn't even work for a simple file/folder link. The code would be quite simple:
Wow, I just learned something. M$ changed the execution of ShellExecute() in Win XP SP3 without a single mentioning in the MSDN. Just tried the example above on XP SP2 and it worked like a charm. On XP SP3 it returned no error but nothing happened either .... W T F (I also tried with a full path, and calling CoInitializeEx like they suggested in MSDN - nothing worked... until I removed the second parameter and specified it like this:
and it worked. Who would've thought. But now, I'm going back to my original question.
Even though it can open my test link to microsoft Paint, it still doesn't open my network connection link - and that is why I started this thread. In this case, ShellExecute() returns 0x2A (that is no error according to the documentation) but nothing happens. If I call GetLastError() right after that, it returns 126, which also doesn't make any sense either.
I'm going nuts over this. Can someone test it on their end? Here's what you need to do. To make a link go to your network connections folder and drag any network connection icon into the folder where you compile the test app to make a link. Rename it to link.lnk and try the code above.
Hmmm well from the error it looks like perhaps there may be a distribution problem...possibly shell32.dll is missing from your target system depending on how your executing it.
Well shellexecute() does fine if you just point it right to the executible that the link points
I mean it seems kind of silly to shellexecute the lnk and when the link isnt there you just cant run the program....You should be checking to see if the program is even installed on the target computer.
FYI You can parse a shortcut with COM and get all the important stuff. You can check for the existance of the lnk, the program, the working directory, whether the information in the theoretical lnk is correct...the path etc.
Last edited by ahoodin; October 25th, 2008 at 03:36 PM.
Hmmm well from the error it looks like perhaps there may be a distribution problem...possibly shell32.dll is missing from your target system depending on how your executing it.
Well shellexecute() does fine if you just point it right to the executible that the link points
I mean it seems kind of silly to shellexecute the lnk and when the link isnt there you just cant run the program....You should be checking to see if the program is even installed on the target computer.
FYI You can parse a shortcut with COM and get all the important stuff. You can check for the existance of the lnk, the program, the working directory, whether the information in the theoretical lnk is correct...the path etc.
No, this is not a distribution problem and shell32.dll isn't missing from my target system. I understand your point about a link that refers to a file, but if you read my question above you'll see that I'm talking about a link that doesn't point to a file. I tried putting it through IShellLink interface, but its GetPath() method simply returns an empty string.
I described in my post above how to make such link:
... go to your network connections folder and drag any network connection icon into the folder where you compile the test app to make a link. Rename it to link.lnk and try the code above.
Can someone please try it? I'm sure there's a way to run it (since it can be done using the Start -> Run command.)
This most certainly is some sort of distribution problem. Not every Windows Install is equal. ERROR_MOD_NOT_FOUND is associated with a screwed up install. Tools that can help are depends.exe, and regedit.
I think that it is a character flaw that I posess as well. I make up my mind occasionally that the bug is one thing or another. In fact I need to keep an open mind to the true cause of the bug, because the reason I have a bug in the first place is due to something I don't know...a base I never covered.
The error code becomes 87 - The parameter is incorrect. If I remove sei.lpVerb and make it equal to NULL, again no error is returned by ShellExecuteEx() but nothing happens either.
Now I'm actually looking for the way to simply run a link. (I may start a separate thread on it.) There should be some interface to do it, right?
FIY, I'm attaching an example of a link that I'm trying to run.
In my program I need the ability to run a link provided by a user (shortcut file with the .lnk extension). I can use ShellExecute on a link that refers to a file, but that API does nothing on my Win XP SP3 if I specify a link to, say, Local Area Network connection. I tried putting it through the IShellLink interface but the GetPath() method simply returns an empty string.
Can someone tell me if there's a uniform way to run a link?
ShellExecute() is definitely not the preferred method. The best way is CreateProcess(). I think calling a Link (with shellexecute) with an open method is probably screwing that up. The .exe preforms the open, not the .lnk. ShellExecute() preforms an operation on a file.
Last edited by ahoodin; October 26th, 2008 at 04:25 PM.
Thanks, Igor. That is a very interesting solution, but unfortunately I'm getting a Security Warning before the link is opened. A window with a question pops up, "Do you want to open or save this file?"
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.