private void chkStartUp_CheckedChanged(object sender, EventArgs e) { if (chkStartUp.Checked == true) { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Create the shortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut( startUpFolderPath + "\\" + Application.ProductName + ".lnk"); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch MyApp"; // shortcut.IconLocation = Application.StartupPath + @"\App.ico"; shortcut.Save(); } else { string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); DirectoryInfo di = new DirectoryInfo(startUpFolderPath); FileInfo[] files = di.GetFiles("*.lnk"); foreach (FileInfo fi in files) { if (fi.ToString() == Application.ProductName + ".lnk") { string shortcutTargetFile = GetShortcutTargetFile(fi.FullName); System.IO.File.Delete(fi.FullName); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)