Skip to content

Instantly share code, notes, and snippets.

@Mierenga
Created February 7, 2017 15:41
Show Gist options
  • Save Mierenga/a8a1fcdbee5555ac9249aab7837da0bd to your computer and use it in GitHub Desktop.
Save Mierenga/a8a1fcdbee5555ac9249aab7837da0bd to your computer and use it in GitHub Desktop.
private string getShortcutPath()
{
string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
return System.IO.Path.Combine(startupPath, "myApp.lnk");
}
private void createStartupShortcut()
{
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(getShortcutPath());
shortcut.Description = "Startup shortcut for myApp";
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
shortcut.Save();
}
private void removeStartupShortcut()
{
string shortcutPath = getShortcutPath();
if (System.IO.File.Exists(shortcutPath)) {
System.IO.File.Delete(shortcutPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment