Solved

Urgent!  Can someone compile this short code VC6.0 (prints windows shortcut info)

Posted on 2004-10-19
6
258 Views
Last Modified: 2010-04-01
Hi.  I need a program that I can execute like this:

<prompt>GetTarget.exe "c:\example\path\somelink.lnk"

Output:
  The TARGET field and nothing else.

Ex:
<prompt>GetTarget.exe "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\Microsoft Office.lnk"

Output:
"C:\Program Files\Microsoft Office\Office\OSA9.EXE" -b -l

I found this code on the web and it looks like this is what I need but I don't have a compile installed and need this functionality soon.
Can someone please compile it for me so I can pass one argument (full path) and have it output the target + args.  If the file is not found or there is no target output nothing.

http://www.codeguru.com/Cpp/COM-Tech/shell/article.php/c1337

Thanks!  This is not a normal practice for me but I need this ASAP and do not have access to VC6.0 at the moment.  I made this worth the max number of points I could.  Thanks again.
0
Comment
Question by:JonAqua
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 500 total points
ID: 12355225
sample in MSDN

HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath)
{
    HRESULT hres;
    IShellLink* psl;
    char szGotPath[MAX_PATH];
    char szDescription[MAX_PATH];
    WIN32_FIND_DATA wfd;
 
    *lpszPath = 0; // assume failure
 
    // Get a pointer to the IShellLink interface.
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (LPVOID*)&psl);
    if (SUCCEEDED(hres))
    {
        IPersistFile* ppf;
 
        // Get a pointer to the IPersistFile interface.
        hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
            
        if (SUCCEEDED(hres))
        {
            WCHAR wsz[MAX_PATH];
 
            // Ensure that the string is Unicode.
            MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH);
 
            // TODO: Check return value from MultiByteWideChar to ensure
                     success.
 
            // Load the shortcut.
            hres = ppf->Load(wsz, STGM_READ);
           
            if (SUCCEEDED(hres))
            {
                // Resolve the link.
                hres = psl->Resolve(hwnd, 0);

                if (SUCCEEDED(hres))
                {
                    // Get the path to the link target.
                    hres = psl->GetPath(szGotPath,
                                        MAX_PATH,
                                        (WIN32_FIND_DATA*)&wfd,
                                        SLGP_SHORTPATH);

                    if (SUCCEEDED(hres))
                    {
                        // Get the description of the target.
                        hres = psl->GetDescription(szDescription, MAX_PATH);

                        if (SUCCEEDED(hres))
                        {
                            hres = StringCbCopy(lpszPath, sizeof(lpszPath),
                                                szGotPath);
                            if (SUCCEEDED(hres))
                            {
                                // Handle success
                            }
                            else
                                // application-defined function
                                HandleErr(hres);
                        }
                    }
                }
            }

            // Release the pointer to the IPersistFile interface.
            ppf->Release();
        }

        // Release the pointer to the IShellLink interface.
        psl->Release();
    }
    return hres;
}
0
 

Author Comment

by:JonAqua
ID: 12356752
Thanks, my problem is I need a compiled binary because I dont have access to Visual Studio at the moment.
0
 

Author Comment

by:JonAqua
ID: 12356764
Nevermind I got it thanks!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question