CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> COM-based Technologies >> Shell Programming


Getting Shortcuts (.lnk) - Target and Arguments
Rating: none

Firo (view profile)
February 13, 1999

Environment: VC6.0 SP2

I saw Michael Taupitz's idea of creating Links (shortcuts) and I realized that there are many times when we stumble across a link in command prompt mode and we have no idea what this .lnk file points to.


(continued)



Here's a function I wrote which returns the Target and Arguments of a .lnk file in a CString. Hope you find it helpful.


CString GetShortcutTarget(const CString LinkFileName)
{
	HRESULT hres;

	CString Link, Temp = LinkFileName;
	Temp.MakeLower();
	if (Temp.Find(".lnk")==-1)           //Check if the name ends with .lnk
		Link = LinkFileName + ".lnk";   //if not, append it
	else
		Link = LinkFileName;

	CString Info;
	Info.Empty();

	IShellLink* psl;

	//Create the ShellLink object
	hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
				IID_IShellLink, (LPVOID*) &psl);

	if (SUCCEEDED(hres))
	{
		IPersistFile* ppf;
		//Bind the ShellLink object to the Persistent File
		hres = psl->QueryInterface( IID_IPersistFile, (LPVOID *) &ppf);
		if (SUCCEEDED(hres))
		{
			WORD wsz[MAX_PATH];
			//Get a UNICODE wide string wsz from the Link path
			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Link, -1, wsz, 					    MAX_PATH);

			//Read the link into the persistent file
			hres = ppf->Load(wsz, 0);

			if (SUCCEEDED(hres))
			{
				//Read the target information from the link object
				//UNC paths are supported (SLGP_UNCPRIORITY)
				psl->GetPath(Temp.GetBuffer(1024), 1024, NULL, 				             SLGP_UNCPRIORITY);
				Temp.ReleaseBuffer();
				Info = Temp;

				//Read the arguments from the link object
				psl->GetArguments(Temp.GetBuffer(1024), 1024);
				Temp.ReleaseBuffer();
				Info += " " + Temp;
			}
		}
	}
	psl->Release();
	//Return the Target and the Argument as a CString
	return Info;
}


Date Posted: 13/02/99

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
How about a DLL to do it? - Legacy CodeGuru (05/04/2001)
Trouble with links to MS system EXEs - Legacy CodeGuru (03/18/2001)
How to run shortcut from my app, just like ordinary .EXE file? - Legacy CodeGuru (12/15/1999)
CoInitialize needed? - Legacy CodeGuru (07/18/1999)
call to ppf->Load(wsz, 0); alwayse return -21... something something - Legacy CodeGuru (07/13/1999)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES