コード例 #1
0
        private bool CreateDesktopIcons(string fileName, string linkName)
        {
            try
            {
                string p = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string s = this.GetBinFile(fileName);
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                string linkFilePath = p + "\\" + linkName + ".lnk";
                if (File.Exists(linkFilePath))
                {
                    File.Delete(linkFilePath);
                }
                IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(linkFilePath);
                shortcut.TargetPath       = s;
                shortcut.Arguments        = "";
                shortcut.Description      = fileName;
                shortcut.WorkingDirectory = Path.Combine(this.installPath.Text, this.binPath);
                shortcut.IconLocation     = string.Format("{0},0", s);
                shortcut.Save();

                this.AddLog("桌面快捷方式创建成功");
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: Loader.cs プロジェクト: Lorain-Li/SelTest
        /// <summary>
        /// 复制文件,并创建快捷方式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CopyThread_DoWork(object sender, DoWorkEventArgs e)
        {
            DirectoryInfo Startup = new DirectoryInfo(Application.StartupPath);

            LabTitle.Text = Startup.Name;
            DirectoryInfo desktop      = new DirectoryInfo(Environment.GetFolderPath((Environment.SpecialFolder.Desktop)));
            String        shortcutPath = Path.Combine(desktop.FullName, Startup.Name + ".lnk");
            String        exePath      = Process.GetCurrentProcess().MainModule.FileName;

            IWshRuntimeLibrary.IWshShell   shell    = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(shortcutPath);
            shortcut.TargetPath       = exePath;
            shortcut.Description      = "应用程序说明";
            shortcut.WorkingDirectory = Environment.CurrentDirectory;
            shortcut.IconLocation     = exePath;
            shortcut.WindowStyle      = 1;
            shortcut.Save();
            BarPross.Maximum = FilesCounter(new DirectoryInfo(Application.StartupPath));
            DeepCopyDirectory(Startup, new DirectoryInfo(Path.Combine("D:\\", Startup.Name)));
            BarPross.Value = BarPross.Maximum;
            if (Startup.Name.ToUpper().Contains("USBBOOT"))
            {
                Process reboot = new Process();
                reboot.StartInfo.FileName = Path.Combine("D:\\", Startup.Name, "run_a0.bat");
                reboot.Start();
            }
            else
            {
                Process reboot = new Process();
                reboot.StartInfo.FileName = Path.Combine("D:\\", Startup.Name, Application.ProductName + ".exe");
                reboot.Start();
            }
            System.Environment.Exit(0);
        }
コード例 #3
0
        private bool CreateStartupMenu()
        {
            try
            {
                string p = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                string s = this.CreateStartupBatFile();
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(p + "\\startup.lnk");
                shortcut.TargetPath       = s;
                shortcut.Arguments        = "";
                shortcut.Description      = "启动";
                shortcut.WorkingDirectory = this.installPath.Text;
                shortcut.IconLocation     = string.Format("{0},0", s);
                shortcut.Save();

                this.AddLog("启动组快捷方式创建成功");
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }