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);
ItemPtr location = Item::get_Desktop();
LinkItemPtr link = new LinkItem(target);
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 = ...;
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
For other members, please check my previous article.
Class LinkItem
Constructors
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