CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 33
  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Running a network link fails

    Hi everyone:


    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?

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Running a network link fails

    Please post code.
    WHat happens when you just type in the full path to the lnk in Start->Run?

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Running a network link fails

    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:
    Code:
    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?

  4. #4
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Running a network link fails

    I wonder if your seeing a security side effect. Perhaps it has something to do with priveleges.
    ahoodin
    To keep the plot moving, that's why.

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Running a network link fails

    Are you sure the path is right ? Did you try with full path to the lnk ?

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Running a network link fails

    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:
    Code:
    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!

  7. #7
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Running a network link fails

    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.
    ahoodin
    To keep the plot moving, that's why.

  8. #8
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Running a network link fails

    Quote Originally Posted by ahoodin
    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.)

  9. #9
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Running a network link fails

    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.

    http://flashexperiments.insh-allah.c...eError126.html

    http://www.codeguru.com/forum/archiv.../t-150019.html

    http://consumerdocs.installshield.co...8433&sliceId=1

    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.
    ahoodin
    To keep the plot moving, that's why.

  10. #10
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Running a network link fails

    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.

    2. If I try this:
    Code:
    SHELLEXECUTEINFO sei = {0};
    sei.cbSize = sizeof(sei);
    sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;
    sei.nShow = SW_SHOW;
    sei.lpVerb = _T("open");
    sei.lpFile = pLinkPath;
    sei.lpParameters = "";
    sei.hwnd = AfxGetMainWnd()->GetSafeHwnd();
    
    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.
    Attached Files Attached Files

  11. #11
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    How to run a link from .lnk file?

    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?

  12. #12
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Running a network link fails

    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.
    ahoodin
    To keep the plot moving, that's why.

  13. #13
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Running a network link fails

    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

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,607

    Re: How to run a link from .lnk file?

    Yep. It's a ShellExecute with appropriate verb specified.
    Code:
    ShellExecute(NULL, "open", "explorer.exe", "C:\\Local Area Connection.lnk", NULL, 0);
    Last edited by Igor Vartanov; October 31st, 2008 at 07:40 AM.
    Best regards,
    Igor

  15. #15
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: How to run a link from .lnk file?

    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?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured