Skip to main content

How can I programatically pin an item that displays a jump list to the start menu in WIN7

I want to add an item to the start menu to display a list of applications that the user can launch. Kind of like a custom menu. I got the WIN API code pack and understand that I can use a jump list for the popup menu part. Not sure how I can pin something to the start menu though. I'm looking for something along the lines of what IE displays.

Solved

Was able to accomplish this using Shell32 library.

public static class VerbNames{
    public static string PinToStartMenu = "Pin to Start Men&u";
    public static string UnpinFromStartMenu = "Unpin from Start Men&u";

    public static string PinToTaskbar = "Pin to Tas&kbar";
    public static string UnpinFromTaskbar = "Unpin from Tas&kbar";
}

public static class DesktopUtil {
    public static void PinItemToStartMenu(string itemPath, string itemName) {
        DoItemVerb(itemPath, itemName, VerbNames.PinToStartMenu);
    }

    public static void UnpinItemFromStartMenu(string itemPath, string itemName) {
        DoItemVerb(itemPath, itemName, VerbNames.UnpinFromStartMenu);
    }

    public static void PinItemToTaskbar(string itemPath, string itemName) {
        DoItemVerb(itemPath, itemName, VerbNames.PinToTaskbar);
    }

    public static void UnpinItemFromTaskbar(string itemPath, string itemName) {
        DoItemVerb(itemPath, itemName, VerbNames.UnpinFromTaskbar);
    }

    private static void DoItemVerb(string itemPath, string itemName, string verb) {
        Shell32.Shell shell = new Shell32.Shell();

        Shell32.Folder folder = shell.NameSpace(itemPath);

        Shell32.FolderItem item = folder.ParseName(itemName);

        DoItemVerb(item, verb);
    }

    private static void DoItemVerb(Shell32.FolderItem item, string verbToDo) {
        Shell32.FolderItemVerbs verbs = item.Verbs();

        foreach (Shell32.FolderItemVerb verb in verbs) {
            if (verb.Name.Equals(verbToDo)) {
                verb.DoIt();
            }
        }
    }
}

Comments