documentation

Tim-Erwin

Commandline Usage

There are two commands: create and parse which are the first argument.

create

pylnk create c:\dir\file.txt shortcut

This command creates a shortcut for a file.

parse

pylnk parse c:\dir\shortcut
pylnk parse c:\dir\shortcut path hot_key

The parse command reads a shortcut file, parses it and prints all information to std out. If a space separated list of properties is given, those properties will be printed out, each on one line in the order they are given.

Programming Interface

Parse an existing LNK

:::python
import pylnk
link = pylnk.parse("C:\\path\\to\\shortcut to file.lnk")
print link.description
print link.path

The parse function creates a Lnk object from an existing LNK file. Currently, only LNKs with paths that start with a drive letter are supported.

Create a LNK for a file

:::python
import pylnk
link = pylnk.for_file("C:\\path\\to\\some file")
link.hot_key = "CONTROL+ALT+F"
link.save("C:\\path\\to\\shortcut to some file")

for_file() takes as first argument the target file to create a shortcut for. As second, optional, argument you can specify the shortcut name and then omit it in the save() method.

Create an empty LNK

:::python
import pylnk
link = pylnk.create("C:\\path\\to\\crafted shortcut")
...
# populate Lnk object here
...
link.save()

If you know how, you can create a shortcut file from scratch with create(). You can leave out the file name there and specify it when saving instead. Creating LNKs from scratch unfortunately needs some knowledge about their internals.

About the .lnk format

  • The definitive source about the .lnk format is of course the official specification.
  • However, it does not specify the most important part of .lnk files. There are two great blog posts that explain that part in detail.
  • Also Jesse Hager has reverse engineered the format (before it was published by Microsoft). He made is findings available including an example of a shortcut file.

Related

Home: Home

MongoDB Logo MongoDB