Announcement

Collapse
No announcement yet.

extract path from shortcut (.lnk) file.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • extract path from shortcut (.lnk) file.

    I have a need to extract the path from a desktop shortcut. Because this shortcut may point to a network path, "search everywhere" is not an option. Unfortunately; my user base cannot be trusted with a dialog box.

    Any ideas how I can extract this path from the .lnk file and use it setup factory?

  • #2
    Re: extract path from shortcut (.lnk) file.

    As far as I know, there is no way to resolve a shell link in Setup Factory 6.0 directly. However, you could write a C++ or VB program that you could run from your setup that goes through the Shell API to resolve the link. Try reading this.

    Comment


    • #3
      Re: extract path from shortcut (.lnk) file.

      thanks for the link; I tried that code and unfortunately; it fails for me.. fails at "GetPath()" call....

      Any other ideas?

      Comment


      • #4
        Re: extract path from shortcut (.lnk) file.

        I take back my other post...

        It fails at

        hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
        IID_IShellLink, (LPVOID*)&psl);

        Anyone out there in C land know what I can do to get around this?

        Thanks.
        -josh

        Comment


        • #5
          Re: extract path from shortcut (.lnk) file.

          I found this function:

          HRESULT ShortCutLib::ShortCut::_ResolveLink(LPCWSTR LnkFile, LPWSTR FilePath,
          LPWSTR LnkDesc,LPWSTR WorkDir)
          {
          CoInitialize(NULL);
          HRESULT hres;
          IShellLink* psl;
          WIN32_FIND_DATA wfd;
          char strfilepath[MAX_PATH];
          char strlnkdesc[INFOTIPSIZE];
          char strworkdir[MAX_PATH];

          USES_CONVERSION;

          hres = CoCreateInstance(CLSID_ShellLink, NULL,
          CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *) &psl);
          if (SUCCEEDED(hres))
          {
          IPersistFile* ppf;
          hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf);
          if (SUCCEEDED(hres))
          {
          hres = ppf->Load(LnkFile, STGM_READ);
          if (SUCCEEDED(hres))
          {
          hres = psl->Resolve(GetDesktopWindow(), 0);
          if (SUCCEEDED(hres))
          {
          hres = psl->GetPath(strfilepath,MAX_PATH, &wfd,
          SLGP_UNCPRIORITY );

          if (SUCCEEDED(hres))
          {
          wcscpy(FilePath, A2W(strfilepath));
          hres = psl->GetDescription(strlnkdesc,INFOTIPSIZE);
          }

          if (SUCCEEDED(hres))
          {
          wcscpy(LnkDesc,A2W(strlnkdesc));
          hres = psl->GetWorkingDirectory(strworkdir,MAX_PATH);
          }

          if (SUCCEEDED(hres))
          {
          wcscpy(WorkDir,A2W(strworkdir));
          }
          }
          }
          ppf->Release();
          }
          psl->Release();
          }
          CoUninitialize();
          return hres;
          }

          You can read the whole article here:

          http://www.codeproject.com/managedcpp/mcppshortcuts.asp

          Comment


          • #6
            Re: extract path from shortcut (.lnk) file.

            Thanks brett!

            I'll try this code.. My C++ is even worse than my C... but I should be able to fake it ..

            Thanks.

            Comment


            • #7
              Re: extract path from shortcut (.lnk) file.

              requires .net -- I don't ahve .net... [img]/ubbthreads/images/icons/frown.gif[/img]

              Comment


              • #8
                Re: extract path from shortcut (.lnk) file.

                Although the article was about .NET, the code that was for the DLL (which includes the function above) was writting in C++, so it does not use or require .NET.

                Comment


                • #9
                  Re: extract path from shortcut (.lnk) file.

                  thanks. Unfortunately; it won't compile with VC 6.0
                  A2W isnt' found, I found a #define in ansiapi.h, but wrong # of parameters.

                  Thanks for looking.. I'll keep plugging away.

                  Comment


                  • #10
                    Re: extract path from shortcut (.lnk) file.

                    Finally found a program that does it nicely.. If anyone needs it; let me know.

                    Comment

                    Working...
                    X