Created
February 7, 2017 15:41
-
-
Save Mierenga/a8a1fcdbee5555ac9249aab7837da0bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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