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?
kirants
October 24th, 2008, 05:57 PM
Please post code.
WHat happens when you just type in the full path to the lnk in Start->Run?
dc_2000
October 24th, 2008, 09:16 PM
Thanks for response.
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:
if((int)::ShellExecute(NULL, "open", "link.lnk", "", NULL, SW_SHOWNORMAL) <= 32)
{
//Error
}
Now it doesn't return an error but it doesn't do anything either. It must have something to do with this XP SP3.
Any ideas?
ahoodin
October 24th, 2008, 10:14 PM
I wonder if your seeing a security side effect. Perhaps it has something to do with priveleges.
kirants
October 24th, 2008, 11:58 PM
Are you sure the path is right ? Did you try with full path to the lnk ?
dc_2000
October 25th, 2008, 02:00 AM
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:
if((int)::ShellExecute(NULL, NULL, "link.lnk", "", NULL, SW_SHOWNORMAL) <= 32)
{
//Error
}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.
Thank you!
ahoodin
October 25th, 2008, 04:24 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.
dc_2000
October 26th, 2008, 12:46 AM
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.)
ahoodin
October 26th, 2008, 03:53 PM
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.
dc_2000
October 26th, 2008, 04:45 PM
Thanks for trying to help, but this is not a distribution problem. Here's why: 1. If I put this link in the Start -> Run, it runs without a problem.
if(!ShellExecuteEx(&sei))
{
//Error
int nErr = GetLastError();
}
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.
dc_2000
October 26th, 2008, 04:59 PM
Hi everyone:
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?
ahoodin
October 26th, 2008, 05:22 PM
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. :thumb: ShellExecute() preforms an operation on a file.
dc_2000
October 26th, 2008, 05:37 PM
Just tried CreateProcess() but it failed as well. As I said earlier, ShellExecute without the "open" verb does nothing.
I'm totally stumped with this thing :(
Igor Vartanov
October 31st, 2008, 08:22 AM
Yep. It's a ShellExecute with appropriate verb specified. ShellExecute(NULL, "open", "explorer.exe", "C:\\Local Area Connection.lnk", NULL, 0);
dc_2000
October 31st, 2008, 05:15 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?"
Is there any way to bypass it?
ahoodin
October 31st, 2008, 06:55 PM
I think your crossposting in order to get your answer. I understand you are trying to get an answer, but crossposting is considered a *no no* on lists in general. Just so you know for the next time. :D
Well I have been thinking about this a bit. You run into a number of troubles. If you execute the lnk on the computer the lnk is on, there will not be trouble. If you are executing the remote .lnk exists on the machine running ShellExecute() the path will not be standard as drive mapping is not always an absolute process on every system. Or do you use the fully qualified network path machine name, domain etc....? :D
Now I think that if you parse the .lnk with COM and execute the process with CreateProcess or ShellExecute, life maybe better.
I think you should post your code to help everybody understand. :thumb: Please only upload source files (.cpp and .h files and a makefile).
Marc G
November 1st, 2008, 08:46 AM
[ merged threads ]
Please keep the discussion on one topic in one thread.
zaryk
November 10th, 2008, 09:45 PM
yall helped me.
binyo66
May 17th, 2009, 09:32 AM
I think what the starter of the thread means running the lnk files that has no path inside, something like microsoft office shortcut. The CreateProcess failed, and the IShellLink::GetPath gave empty string. "cmd start" or explorer could execute the lnk file well. anyone knows what are the API the "cmd start" using to launch the microsoft office shortcut ?
binyo66
May 17th, 2009, 10:33 AM
Nevermind, i found it. I am using ShellExecuteEx :D
ahoodin
May 17th, 2009, 08:10 PM
Don't use old threads. Start your own thanks!
bradman
July 7th, 2009, 06:46 PM
Can you please provide solution for this issue.
I am running into the same issue. I need to execute a shortcut (non-file based short cut, example: Wireless Network Connections") from my C# code.
I have trying to use ShellExecute and ShellExecuteEx as well to display the wireless network connections dialog
This is a very old thread, over a year old. The original post has already been answered.
Please don't ask this question on such an old thread. Start a new one in the C# section. That's just more polite,
and better netticut.
Also try advanced search your topic.
Thanks.
dc_2000
July 8th, 2009, 02:36 AM
Yes, it is an old thread and no, I still don't have an answer to my original question. (So if you find it please post it here.)
Here's what I was able to find so far:
(1) In case you're opening a short-cut to a file or anything that is represented by a non-virtual object, it works if you specify an empty string as the lpOperation parameter for ShellExecute() or lpVerb for ShellExecuteEx(). If it is a file, then use "open".
(2) In some rare cases the verb "properties" may open the properties window for a virtual short-cut.
(3) What is very annoying is that sometimes ShellExecute() and ShellExecuteEx() may return success (under Windows XP SP3) even though nothing gets opened.
(4) CreateProcess() obviously does not work on short-cuts, as well as an older alternative WinExec().
(5) I was able to open pretty much most of the shortcuts with the above approach, except the one stated below (see picture attached). Somehow none of the above approaches worked on a short-cut to a Local Area network connection (the default behavior is to show the status window of the connection), or a Dial-up Connection icon. And there's absolutely no documentation from MS to support this.
Hope this helps.
carl666
July 8th, 2009, 11:12 AM
Somehow none of the above approaches worked on a short-cut to a Local Area network connection (the default behavior is to show the status window of the connection), or a Dial-up Connection icon. And there's absolutely no documentation from MS to support this.
???
Just use the CLSID. It has always worked since Windows 95 !
dc_2000
July 8th, 2009, 12:35 PM
???
Just use the CLSID. It has always worked since Windows 95 !OK, then. Why don't you share with us and post a code sample?
bradman
July 8th, 2009, 05:47 PM
???
Just use the CLSID. It has always worked since Windows 95 !
Can you please provide code snippet to launch non-file based short cuts (like wireless network connection etc)
ahoodin
July 8th, 2009, 09:08 PM
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.
__________________
You can read the contents of the shortcut with COM, and then execute the program passing the parameters using CreateProcess(), all from information gleaned via COM. As I have said.
Here is an example of the code:
COM Link (http://www.codeproject.com/KB/shell/create_shortcut.aspx)
Remember, Google and the MSDN are your friends.
Yes, it is an old thread and no, I still don't have an answer to my original question. (So if you find it please post it here.)
Here's what I was able to find so far:
(1) In case you're opening a short-cut to a file or anything that is represented by a non-virtual object, it works if you specify an empty string as the lpOperation parameter for ShellExecute() or lpVerb for ShellExecuteEx(). If it is a file, then use "open".
(2) In some rare cases the verb "properties" may open the properties window for a virtual short-cut.
(3) What is very annoying is that sometimes ShellExecute() and ShellExecuteEx() may return success (under Windows XP SP3) even though nothing gets opened.
(4) CreateProcess() obviously does not work on short-cuts, as well as an older alternative WinExec().
(5) I was able to open pretty much most of the shortcuts with the above approach, except the one stated below (see picture attached). Somehow none of the above approaches worked on a short-cut to a Local Area network connection (the default behavior is to show the status window of the connection), or a Dial-up Connection icon. And there's absolutely no documentation from MS to support this.
Hope this helps.
dc_2000
July 9th, 2009, 12:56 AM
Remember, Google and the MSDN are your friends.ahoodin, do you think I didn't try Googling for the past year? Also, before giving that lead in your previous post did you try it yourself?
Well, if you did, you'd learn that it works only with links that have a physical file attached to them. In any other case (any shortcut to a virtual Windows object -- anything from a control panel, network connection, or, as in my case, a Local Area Network connection) will not succeed with a simple IShellLink/IPersistFile approach. If, for some reason, bradman, is able to have his link return a meaningful path with that method, then he is probably not using ShellExecute correctly. Again, all he has to do in case of a simple file link is to call it like this:
//For a file link only
if(int(ShellExecute(NULL, _T(""), lpLnkFilePath, NULL, NULL, SW_SHOW)) > 32)
{
//Success
//But NOT guaranteed that something will actually open!
}
For anyone else who doesn't have a simple file link and doesn't want to waste time trying the above-mentioned "Create and resolve a shortcut" approach, let me tell you what happens:
1. IPersistFile::Load() succeeds
2. IShellLink::Resolve() succeeds
3. IShellLink::GetPath() fails with return code of 1 and empty path
4. IShellLink::GetDescription() succeeds but returns an empty string.
ahoodin
July 9th, 2009, 01:05 PM
Well the fact remains the the methods you can use to do this are part of COM. You should probably try to find some reference material on COM. Why is it that 1000 vb programmers can write a malicious script to do this easily but C++ programmers can't. We must be getting lazy, and not finding reference materials or something.
dc_2000
July 9th, 2009, 01:22 PM
Yes, I'm with you on this one. My gut feeling tells me too that it's done thru COM, but unfortunately I'm not that well versed in it to know. (So if someone finds out, it'd be nice if you guys post it on this thread.) One way to know is to step into what Start -> Run does with a kernel mode debugger, since it can easily handle running those links. I just don't have time for it now :(
ykhodak
December 6th, 2011, 11:38 PM
I confirm the problem dc_2000 described for XP sp3. Here is how I start links
The IShellLink::GetPath would return something like C:\WINDOWS\Installer\{00000409-78E1-11D2-B60F-006097C998E7}\wordicon.exe
this is valid file and running GetFileAttributes would return 33 which means FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY
2.for Dial-up Connection
IShellLink::GetPath returns empty string. Do IShellLink::GetIDList and then ShellExecuteEx with
ShExecInfo.fMask = SEE_MASK_IDLIST;
normal links can be launched ShellExecute (NULL, _T("open"), link_path.lnk, NULL, NULL, SW_SHOWNORMAL);
the folder C:\WINDOWS\Installer means something special for explorer because it is not showing it by default in folders tree. You can list the folder in cmd.exe also it is visible in DataRotunda (some file utility).
san007
December 9th, 2011, 10:22 AM
I am confused about the path.If it's ok then sometimes C++ creates some boring problem but critical.I have to know actually what happen.I will try if i get any problem with it.If you need any help to recover your lost data from you hard drive or anything else you can visit my site.Here it is.
data recovery san diego (http://www.sandiegopchelp.com/services/data-recovery)
raid data recovery san diego (http://www.sandiegopchelp.com/services/data-recovery/raid)
Thanks
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.