Save() public method

Saves the shortcut to ShortCutFile.
public Save ( ) : void
return void
        private void btnSendTo_Click(object sender, EventArgs e)
        {
            string sendToPath = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
            string linkPath = Path.Combine(sendToPath, Application.ProductName + ".lnk");

            using (ShellLink shortcut = new ShellLink())
            {
                shortcut.Target = Application.ExecutablePath;
                shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
                shortcut.Description = Application.ProductName;
                shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
                shortcut.Save(linkPath);
            }
            SendToLinkCheck();
        }
 /// <summary>
 /// Registers the specified assembly to be launched at startup.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="commandLine">The command line.</param>
 public void RegisterStartup(Assembly assembly, string commandLine = null)
 {
     using (var shortcut = new ShellLink())
     {
         var location = assembly.Location;
         shortcut.Target = location;
         shortcut.WorkingDirectory = Path.GetDirectoryName(location);
         shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
         shortcut.IconPath = location;
         shortcut.IconIndex = 0;
         if (commandLine != null)
             shortcut.Arguments = commandLine;
         shortcut.Save(GetShortcutPath(assembly));
     }
 }
示例#3
0
        private void UpdateUserShortcuts()
        {
            try
            {

                UpdateStatus("Updating Links...");
                var newWorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "OCTGN",
                                           "OCTGN");
                var newTarget = Path.Combine(newWorkingDirectory, "octgn.exe");

                var fileList = new List<string>();

                var sPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
                if(Directory.Exists(sPath))
                    fileList.AddRange(Directory.GetFiles(sPath, "*.lnk", SearchOption.AllDirectories));

                sPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                if(Directory.Exists(sPath))
                    fileList.AddRange(Directory.GetFiles(sPath, "*.lnk", SearchOption.AllDirectories));

                //I guess doing a recursive search covers all pinned shortcuts in the taskbar and start menu as well in 7 and above
                sPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"Microsoft","Internet Explorer","Quick Launch");
                if(Directory.Exists(sPath))
                    fileList.AddRange(Directory.GetFiles(sPath, "*.lnk", SearchOption.AllDirectories));

                //Look through files for an octgn link
                foreach( var fs in fileList)
                {
                    try
                    {
                        using(var s = new ShellLink(fs))
                        {
                            var finfo = new FileInfo(s.Target);
                            if (finfo.Name.ToLowerInvariant() != "octgn.exe")
                                continue;
                            if (s.Target.ToLowerInvariant() == newTarget.ToLowerInvariant() &&
                                s.WorkingDirectory.ToLowerInvariant() == newWorkingDirectory.ToLowerInvariant()) continue;
                            s.Target = newTarget;
                            s.WorkingDirectory = newWorkingDirectory;
                            s.Save();
                        }
                    }
                    catch (Exception e)
                    {
            #if(DEBUG)
                        UpdateStatus(String.Format("[UpdateLink Failure] {0}",e.Message));
            #endif
                    }
                }
            }
            catch (Exception e )
            {
                new ErrorWindow(e).Show();
            }
        }
示例#4
0
        public void MakeDesktopShortcut()
        {
            using (ShellLink shortcut = new ShellLink())
            {
                var fi = new FileInfo(Assembly.GetExecutingAssembly().Location);
                string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

                shortcut.Target = fi.FullName;
                shortcut.Arguments = "-run";
                shortcut.WorkingDirectory = RootPath;
                if (this.LatestManifest != null)
                    shortcut.Description = this.LatestManifest.title;
                else
                    shortcut.Description = fi.Name + " - run";
                shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;

                shortcut.IconPath = AppPath + "\\favicon.ico";

                var fname = new string(shortcut.Description.Where(ch => !Path.GetInvalidFileNameChars().Contains(ch)).ToArray());
                shortcut.Save(desktopPath + "/" + fname + ".lnk");
            }
        }
        void CreateShortcutFor(string fileName, string description)
        {
            using (ShellLink shortcut = new ShellLink())
            {
                // The file that the .lnk file links to
                string target = ComponentStorage.GetValue<string>(FrbdkSetupComponent.Path) + fileName;
                shortcut.Target = target;
                shortcut.WorkingDirectory = Path.GetDirectoryName(target);
                shortcut.Description = description;
                shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;

                // Where to save the .lnk file
                shortcut.Save(StartMenuFolder + FileManager.RemovePath(FileManager.RemoveExtension(fileName)) + ".lnk");
            }
        }
示例#6
0
文件: form.cs 项目: xbojer/devel_vm
        private void finalize()
        {
            log("Clearing temporary directory...");
            Directory.Delete(tempDir, true);

            log("Adding autostart reg entry...");
            RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            if (regkey != null)
            {
                regkey.SetValue("Devel VM", mainexe);
                regkey.Close();
            }

            string smDir = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
            if (Directory.Exists(Path.Combine(smDir, "Devel VM")))
            {
                log("Clearing [" + Path.Combine(smDir, "Devel VM") + "]...");
                Directory.Delete(Path.Combine(smDir, "Devel VM"), true);
            }
            smDir = Path.Combine(smDir, "Devel VM");
            log("Creating [" + Path.Combine(smDir, "Devel VM") + "]...");
            Directory.CreateDirectory(smDir);

            log("Create StartMenu shortcut...");
            try
            {
                ShellLink link = new ShellLink();
                link.Target = mainexe;
                link.WorkingDirectory = Path.GetDirectoryName(mainexe);
                link.IconPath = mainexe;
                link.IconIndex = 0;
                link.Description = "Devel VM Manager";
                link.Save(Path.Combine(smDir, "Devel VM.lnk"));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create DeskTop Shortcut...\r\n" +
                                "App_Path = " + mainexe + "\r\n" +
                                "Exception: " + ex.Message.ToString(),
                                "ShortCut Creation Error:");
                Program.Exterminate();
            }

            pb.Value = 100;

            if (rebootRequired)
            {
                log("Finished! Reboot required...");
                MessageBox.Show("Uruchom ponownie komputer aby korzystać z Devela! W razie problemów z uruchomieniem maszyny po restarcie, skontaktuj się z administratorami.", "Devel VM Installer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                log("Finished! Starting app...");
                Program.execute(mainexe, "/r", true, true);
            }
        }
示例#7
0
        public static void UpdateMenu(ContextMenuStrip menu)
        {
            menu.Items.Clear();

            foreach (var plan in PowerPlanManager.FindAll())
            {
                var item = new ToolStripMenuItem
                    {
                        Text = plan.Name,
                        Tag = plan.Guid,
                        Checked = (plan.Guid == PowerPlanManager.Active.Guid)
                    };

                item.Click += delegate(object sender, EventArgs e)
                    {
                        PowerPlanManager.Active = new PowerPlan
                            {
                                Name = null,
                                Guid = (Guid) ((ToolStripMenuItem) sender).Tag
                            };
                    };

                menu.Items.Add(item);
            }

            menu.Items.Add(new ToolStripSeparator());

            // Charge indicator
            var charge = new ToolStripMenuItem {Text = ChargeString(), Enabled = false};

            menu.Items.Add(charge);

            // Version info
            var version = new ToolStripMenuItem {Text = String.Format(Strings.VersionString, Version), Enabled = false};

            menu.Items.Add(version);

            menu.Items.Add(new ToolStripSeparator());

            // Control panel shortcut
            var cpanel = new ToolStripMenuItem {Text = Strings.MoreSettings};
            cpanel.Click += (sender, e) => Process.Start(ControlExe, "/name Microsoft.PowerOptions");

            menu.Items.Add(cpanel);

            // Autostart
            var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup),
                                            "PowerPlanSwitcher.lnk");

            var autostart = new ToolStripMenuItem
                {
                    Text = Strings.Autostart,
                    Checked = File.Exists(shortcutPath),
                    CheckOnClick = true
                };

            autostart.Click += (sender, args) =>
                {
                    if (((ToolStripMenuItem) sender).Checked)
                    {
                        File.Delete(shortcutPath);
                        var shortcut = new ShellLink
                            {
                                Target = Application.ExecutablePath,
                                WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath),
                                Description = "Power Plan Switcher",
                                DisplayMode = ShellLink.LinkDisplayMode.edmNormal
                            };
                        shortcut.Save(shortcutPath);
                    }
                    else
                    {
                        File.Delete(shortcutPath);
                    }
                };

            menu.Items.Add(autostart);

            // Exit
            var exit = new ToolStripMenuItem {Text = Strings.Exit};
            exit.Click += delegate
                {
                    _trayIcon.Visible = false;
                    Application.Exit();
                };

            menu.Items.Add(exit);
        }
 private void CreateStartMenuIcon(string path)
 {
     var startPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs");
     using (ShellLink shortcut = new ShellLink())
     {
         shortcut.Target = Path.Combine(path, "MediaCrush.exe");
         shortcut.Description = "MediaCrush";
         shortcut.WorkingDirectory = path;
         shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
         shortcut.Save(Path.Combine(startPath, "MediaCrush.lnk"));
     }
 }