c# start menu style listbox

205 Views Asked by At

Hey everyone I am working on a start menu style program and would like to know how I get pinned programs and all programs list. I started some research and will post what I found so you can all help fill the gaps.

For getting program icons I found this...

public static Icon IconFromFilePath(string filePath)
{
    var result = (Icon)null;

    try
    {
        result = Icon.ExtractAssociatedIcon(filePath);
    }
    catch (System.Exception)
    {
        // swallow and return nothing. You could supply a default Icon here as well
    }

    return result;
}

For getting all programs and pinned programs I find these paths...

%USERPROFILE%\appdata\Roaming\Microsoft\Windows\Start Menu\Programs

C:\ProgramData\Microsoft\Windows\Start Menu\

What are these locations and how does the startmenu utlise these? How can I use them? Hope I am not being to brief but wanted to show I am really working to solve this problem and have been searching a ton. Thanks!

1

There are 1 best solutions below

2
On BEST ANSWER

To begin with, you can get the list of pinned programs for a user using:

%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu

Credit to https://superuser.com/a/171129

Both that folder, and the ones you already found, contain all the shortcuts for the Start Menu. You can get the files using Directory.EnumerateFiles or Directory.GetFiles. Once you have the list of files, you'll need to create ViewModel objects for each of them:

public class StartMenuItem
{
    public Image Icon {get; set;}
    public String LinkPath {get; set;}
}

Create a collection of these and bind your list view ItemSource to it. Finally, to start the application, you can just use Process.Start:

ProcessStartInfo info = new ProcessStartInfo ( "example.lnk" );
info.CreateNoWindow = true;
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
info.RedirectStandardInput = true;
Process whatever = Process.Start( info );

See Run application via shortcut using Process.Start C# for more information.