Solved

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

Posted on 2004-10-19
6
230 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now