Get information about Windows shortcuts in C#


This post explains how to get information about Windows shortcuts. The post has two parts. The first explains how to get the information. The second explains how to create shortcuts.

Getting Shortcut Information

This example uses the following GetShortcutInfo method to get information about shortcuts.

// Get information about this link.
// Return an error message if there's a problem.
private string GetShortcutInfo(string full_name,
    out string name, out string path, out string descr,
    out string working_dir, out string args)
    name = "";
    path = "";
    descr = "";
    working_dir = "";
    args = "";
        // Make a Shell object.
        Shell32.Shell shell = new Shell32.Shell();

        // Get the shortcut's folder and name.
        string shortcut_path =
            full_name.Substring(0, full_name.LastIndexOf("\\"));
        string shortcut_name =
            full_name.Substring(full_name.LastIndexOf("\\") + 1);
        if (!shortcut_name.EndsWith(".lnk"))
            shortcut_name += ".lnk";

        // Get the shortcut's folder.
        Shell32.Folder shortcut_folder =

        // Get the shortcut's file.
        Shell32.FolderItem folder_item =

        if (folder_item == null)
            return "Cannot find shortcut file '" + full_name + "'";                
        if (!folder_item.IsLink)
            return "File '" + full_name + "' isn't a shortcut.";

        // Display the shortcut's information.
        Shell32.ShellLinkObject lnk =
        name = folder_item.Name;
        descr = lnk.Description;
        path = lnk.Path;
        working_dir = lnk.WorkingDirectory;
        args = lnk.Arguments;
        return "";
    catch (Exception ex)
        return ex.Message;

The program first creates a Shell32.Shell object to work with the Windows shell. It uses that object’s NameSpace method to get a Folder object representing the folder that contains the shortcut of interest. It then uses that object’s Items collection to get the shortcut’s name and a ShellLinkObject representing the shortcut. From that object, the method finally gets the rest of the information it needs.

If you look closely at the picture, you’ll see that in that example the shortcut’s …

  • … name was “Signature”
  • … description was “Open the file sig.txt”
  • … path was the path to the WordPad executable
  • … working directory was my desktop
  • … arguments was “sig.txt”

So when I double-click this shortcut, it starts WordPad and opens the file sig.txt on my desktop.

Making Shortcuts

I tested this in Windows 10. The details may differ slightly in other versions of Windows.

To create a shortcut, right-click on the desktop or in a folder, select New > Shortcut as shown below.


This makes Windows display the following dialog.


Enter the path to the program that you want to execute followed by any parameters that you want to pass into that program. In this example, the program is wordpad.exe and the parameter is the name of the file (sig.txt) that WordPad should edit.

Note that paths and parameters that include spaces should be surrounded by quotes as shown in the picture.

After you fill in the program and its parameters, click Next to display the following dialog.


Enter the name that you want to give the shortcut here and click Finish to create the shortcut.

To fine-tune the shortcut, right-click on it and select Properties to display the following dialog.


Here you can enter the start directory (in the Start In field) and the description (in the Comment field).

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in system and tagged , , , , , , , , , . Bookmark the permalink.

6 Responses to Get information about Windows shortcuts in C#

  1. Pingback: Получить информацию о ярлыке Windows в C#

  2. vistaero says:

    Why do I need to run it as administrator to get info about shortcuts in Users\Public\Desktop? explorer.exe can get info about them and is definitely not running as administrator.

    • RodStephens says:

      It works for me without admin privileges. I don’t know know why you would need elevated permissions, unless perhaps the link is in a folder where you don’t have permission to read the link’s properties.

  3. Robert Wilkinson says:

    Remember to add a reference to Shell32.dll from the Windows\System32

  4. Bagdasaryan Alexander says:

    What “using [library name];” do you use?

    • RodStephens says:

      The best way to get that kind of information and other details that are not covered in the post’s text is to download the example program and look at the source code.

      This example needs a reference to the COM library “Microsoft Shell Controls and Automation,” but I don’t think it needs any special using directives. The only ones it needs are:

      using System;
      using System.Windows.Forms;

      The key piece is the Shell class, and that is in the Shell32 namespace. You could use “using Shell32,” but this example explicitly uses the namespace when it uses the class as in:

      // Make a Shell object.
      Shell32.Shell shell = new Shell32.Shell();

Comments are closed.