/* BeejBløg */

Nov 22, 2016 - 1 minute read - Comments -

ListShortcuts.csx

#r “Interop.IWshRuntimeLibrary.dll”

//generated by referencing "Windows Script Host Object Model" in Visual Studio project


//from here: https://stackoverflow.com/a/4909475/813599
using IWshRuntimeLibrary;
using System.Text.RegularExpressions;

var wsh = new WshShell();

var shortcutFileNames = System.IO.Directory.EnumerateFiles(Env.ScriptArgs[0], "*.lnk");
var wshShortcuts = new Dictionary<String, IWshShortcut>();
foreach (var shortcutFileName in shortcutFileNames)
  wshShortcuts[Regex.Match(shortcutFileName, ".*?- (.*?).lnk").Groups[1].Value] = (IWshShortcut)wsh.CreateShortcut(shortcutFileName);

//var maxFileNameLength = wshShortcuts.Max(kv=>kv.Key.Length);

Console.WriteLine("Display Name | Target | Arguments");
Console.WriteLine("--- | --- | ---");
foreach(var sc in wshShortcuts)
  Console.WriteLine($"{sc.Key} | {sc.Value.TargetPath} | {sc.Value.Arguments}");

sample output

image