Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ACF Does Shell - Part 2

0.00/5 (No votes)
30 Jun 2004 1  
This article shows how to create and open shell link with the WinShell library built on ACF.

Introduction

In my previous article ACF Does Shell � Part 1, I talked about how to use the Item class to navigate Windows Shell and retrieve item information. In this article, I will show you how to use the Item and LinkItem classes to create and open shell links (shortcuts). If you are not familiar with the Item class, please check my previous article first.

Creating shell links

The following code snippet shows how to create a link to "My Documents" and then save it to desktop:

ItemPtr target = new Item(SpecialFolder::Personal); // My Documents

ItemPtr location = Item::get_Desktop(); // Desktop


LinkItemPtr link = new LinkItem(target); // The link

link->Save(location);

As you can see, the API is very straightforward.

Opening existing shell links

The following code snippet shows how to open an existing link file and retrieve its properties (description, target, arguments, etc.):

StringPtr path = ...; // Path to a file

ItemPtr item = new Item(path);

if (item->IsLink) {
    LinkItemPtr link = item->LinkItem;

    StringPtr description = link->Description;
    StringPtr targetPath = link->Target->FileSysPath;
    StringPtr args = link->Arguments;
    StringPtr dir = link->WorkingDirectory;
}

The sample application demonstrates how to use these classes.

Class Item

Properties

  • bool IsLink;

    Gets a value indicating whether this object is a shortcut.

  • LinkItemPtr LinkItem;

    Gets a LinkItem object representing a shortcut item.

For other members, please check my previous article.

Class LinkItem

Constructors

  • LinkItem();

    Constructs a new shortcut.

  • LinkItem(Item* target);

    Constructs a new shortcut with the specified target.

Properties

  • StringPtr Description;

    Gets or sets the description string.

  • ItemPtr Target;

    Gets or sets the target.

  • StringPtr Arguments;

    Gets or sets the command-line arguments.

  • StringPtr WorkingDirectory;

    Gets or sets the working directory.

  • bool IsDirty;

    Gets a value indicating whether this object is dirty since it was last saved.

Methods

  • void Resolve();

    Resolves the shortcut. See IShellLink::Resolve.

  • void Save();

    Saves the shortcut. See IPersistFile::Save.

  • void Save(Item* parentFolder);

    Saves the shortcut to the specified location. See IPersistFile::Save.

  • void Save(Item* parentFolder, String* name, bool rememberSaveLocation = true);

    Saves the shortcut to the specified location with the specified name. See IPersistFile::Save.

Reference

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here