/// <summary>
        /// 在桌面创建快捷方式
        /// </summary>
        /// <param name="ShortcutName">快捷方式名称</param>
        /// <param name="TargetPath">快捷方式目标路径</param>
        /// <returns>true:创建成功, false:创建失败,已存在</returns>
        public static bool CreateShortcutOnDesktop(string ShortcutName, string TargetPath)
        {
            //添加引用 (com->Windows Script Host Object Model),using IWshRuntimeLibrary;
            String shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), ShortcutName + ".lnk");

            //有相同快捷方式,不创建
            if (System.IO.File.Exists(shortcutPath))
            {
                return(false);
            }
            //没有相同快捷方式,创建
            else
            {
                IWshShell   shell    = new WshShell();
                WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(shortcutPath);
                //目标
                shortcut.TargetPath = TargetPath;
                //目标后面跟的参数,会有个空格隔开
                //shortcut.Arguments = "";
                //备注
                //shortcut.Description = "";
                //起始位置
                //shortcut.WorkingDirectory = Environment.CurrentDirectory;//程序所在文件夹,在快捷方式图标点击右键可以看到此属性
                //shortcut.WorkingDirectory = "";
                //图标,该图标是应用程序的资源文件
                //shortcut.IconLocation = exePath;
                //快捷键
                //shortcut.Hotkey = "CTRL+SHIFT+W";//热键,发现没作用,大概需要注册一下
                shortcut.WindowStyle = 1;
                shortcut.Save();
                return(true);
            }
        }
示例#2
0
        public static string GetFileNameFromDropObject(IDataObject dataObject)
        {
            string[] fileNames = (string[])dataObject.GetData("FileNameW");
            string   fileName  = null;

            if (fileNames != null)
            {
                fileName = fileNames[0];
            }
            if (fileName == null)
            {
                return(null);
            }
            if (fileName.EndsWith(".lnk"))
            {
                WshShell    shell    = new WshShell();
                WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(fileName);

                fileName = shortcut.TargetPath;
            }
            else if (fileName.EndsWith(".website"))
            {
                fileName = GetUrlFromWebsiteFile(fileName);
            }
            return(fileName);
        }
 private void BrowseFile()
 {
     using (OpenFileDialog dlg = new OpenFileDialog())
     {
         dlg.Filter = this.FileFilter;
         //取消获取lnk目标路径,可选中UWP快捷方式
         dlg.DereferenceLinks = false;
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             ItemFilePath = dlg.FileName;
             string extension = Path.GetExtension(dlg.FileName).ToLower();
             if (extension == ".lnk")
             {
                 using (WshShortcut shortcut = new WshShortcut(dlg.FileName))
                 {
                     if (File.Exists(shortcut.TargetPath))
                     {
                         ItemFilePath = shortcut.TargetPath;
                     }
                 }
             }
             ItemText = Path.GetFileNameWithoutExtension(dlg.FileName);
         }
     }
 }
        public static void CreateShortcutOnDesktop()
        {
            //添加引用 (com->Windows Script Host Object Model),using IWshRuntimeLibrary;
            string shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ChobitsLive Minecraft.lnk");

            if (!System.IO.File.Exists(shortcutPath))
            {
                // 获取当前应用程序目录地址
                string    exePath = Process.GetCurrentProcess().MainModule.FileName;
                IWshShell shell   = new WshShell();
                // 确定是否已经创建的快捷键被改名了
                foreach (var item in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "*.lnk"))
                {
                    WshShortcut tempShortcut = (WshShortcut)shell.CreateShortcut(item);
                    if (tempShortcut.TargetPath == exePath)
                    {
                        return;
                    }
                }
                WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(shortcutPath);
                shortcut.TargetPath       = exePath;
                shortcut.Arguments        = "";                           // 参数
                shortcut.Description      = "ChobitsLive社团MC服务器客户端";
                shortcut.WorkingDirectory = Environment.CurrentDirectory; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
                shortcut.IconLocation     = exePath;                      //图标,该图标是应用程序的资源文件
                //shortcut.Hotkey = "CTRL+SHIFT+W";//热键,发现没作用,大概需要注册一下
                shortcut.WindowStyle = 1;
                shortcut.Save();
            }
        }
        /// <summary>
        /// スタートアップ登録
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            string shortcutPath = getShortcutPath();
            string targetPath   = Assembly.GetExecutingAssembly().Location;

            WshShell    shell    = new WshShell();
            WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(shortcutPath);

            shortcut.TargetPath = targetPath;
            //アイコンのパス
            shortcut.IconLocation = targetPath + ",0";
            // 引数
            //shortcut.Arguments = "/a /b /c";
            // 作業フォルダ
            shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
            // 実行時のウィンドウの大きさ 1:通常 3:最大化 7:最小化
            shortcut.WindowStyle = 1;
            // コメント
            shortcut.Description = "そら時計スタートアップ登録";
            shortcut.Save();

            //後始末
            Marshal.FinalReleaseComObject(shortcut);
            Marshal.FinalReleaseComObject(shell);
        }
        private void AddNewItem()
        {
            NewItem newItem = new NewItem();

            this.InsertItem(newItem, 0);
            newItem.AddNewItem += (sender, e) =>
            {
                using (NewLnkFileDialog dlg = new NewLnkFileDialog())
                {
                    dlg.FileFilter = $"{AppString.Dialog.Program}|*.exe;*.bat;*.cmd;*.vbs;*.vbe;*.js;*.jse;*.wsf";
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    string lnkPath = $@"{SendToPath}\{ObjectPath.RemoveIllegalChars(dlg.ItemText)}.lnk";
                    lnkPath = ObjectPath.GetNewPathWithIndex(lnkPath, ObjectPath.PathType.File);
                    using (WshShortcut shortcut = new WshShortcut(lnkPath))
                    {
                        shortcut.TargetPath       = dlg.ItemFilePath;
                        shortcut.WorkingDirectory = Path.GetDirectoryName(dlg.ItemFilePath);
                        shortcut.Arguments        = dlg.Arguments;
                        shortcut.Save();
                    }
                    DesktopIni.SetLocalizedFileNames(lnkPath, dlg.ItemText);
                    this.InsertItem(new SendToItem(lnkPath), 2);
                }
            };
        }
示例#7
0
        /// <summary>
        /// 创建桌面快捷方式
        /// </summary>
        private void CreateShortcutOnDesktop()
        {
            String shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Piano.lnk");

            if (System.IO.File.Exists(shortcutPath))
            {
                System.IO.File.Delete(shortcutPath);
            }
            // 获取当前应用程序目录地址
            String    exePath = textBox1.Text + "/Piano/Pinao.exe";
            IWshShell shell   = new WshShell();

            // 确定是否已经创建的快捷键被改名了
            foreach (var item in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "*.lnk"))
            {
                WshShortcut tempShortcut = (WshShortcut)shell.CreateShortcut(item);
                if (tempShortcut.TargetPath == exePath)
                {
                    return;
                }
            }
            WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(shortcutPath);

            shortcut.TargetPath       = exePath;
            shortcut.Arguments        = "";                           // 参数
            shortcut.Description      = "CACode's For Piano";
            shortcut.WorkingDirectory = Environment.CurrentDirectory; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
            shortcut.IconLocation     = exePath;                      //图标,该图标是应用程序的资源文件
                                                                      //shortcut.Hotkey = "CTRL+SHIFT+W";//热键,发现没作用,大概需要注册一下
            shortcut.WindowStyle = 1;
            shortcut.Save();
        }
示例#8
0
        public static string GetPathFromLnkFile(string lnkFilePath)
        {
            WshShell    shell    = new WshShell();
            WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(lnkFilePath);

            return(shortcut.TargetPath);
        }
        } //Exit Option

        private void CreateShortcut(string shortcutPathName, bool create)
        {
            if (create)
            {
                try
                {
                    string      shortcutTarget = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, appname + ".exe");
                    WshShell    myShell        = new WshShell();
                    WshShortcut myShortcut     = (WshShortcut)myShell.CreateShortcut(shortcutPathName);
                    myShortcut.TargetPath       = shortcutTarget;                               //The exe file this shortcut executes when double clicked
                    myShortcut.IconLocation     = shortcutTarget + ",0";                        //Sets the icon of the shortcut to the exe`s icon
                    myShortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath; //The working directory for the exe
                    myShortcut.Arguments        = "";                                           //The arguments used when executing the exe
                    myShortcut.Save();                                                          //Creates the shortcut
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
            else
            {
                try
                {
                    if (System.IO.File.Exists(shortcutPathName))
                    {
                        System.IO.File.Delete(shortcutPathName);
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
        }
示例#10
0
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        /// <param name="path">快捷方式路径</param>
        /// <param name="targetPath">目标路径</param>
        public static void CreateShortcut(string path, string targetPath)
        {
            WshShell    shell    = new WshShellClass();
            WshShortcut shortcut = shell.CreateShortcut(path) as WshShortcut;

            shortcut.TargetPath = targetPath;
            shortcut.Save();
        }
            protected override void InitializeComponents()
            {
                base.InitializeComponents();
                this.Controls.AddRange(new Control[] { rdoFile, rdoFolder });
                rdoFile.Top    = rdoFolder.Top = btnOk.Top;
                rdoFile.Left   = lblCommand.Left;
                rdoFolder.Left = rdoFile.Right + 20.DpiZoom();

                btnBrowse.Click += (sender, e) =>
                {
                    if (rdoFile.Checked)
                    {
                        BrowseFile();
                    }
                    else
                    {
                        BrowseFolder();
                    }
                };

                btnOk.Click += (sender, e) =>
                {
                    if (ItemText.IsNullOrWhiteSpace())
                    {
                        MessageBoxEx.Show(AppString.MessageBox.TextCannotBeEmpty);
                    }
                    else if (ItemFilePath.IsNullOrWhiteSpace())
                    {
                        MessageBoxEx.Show(AppString.MessageBox.CommandCannotBeEmpty);
                    }
                    else if (rdoFile.Checked && !ObjectPath.GetFullFilePath(ItemFilePath, out _))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.FileNotExists);
                    }
                    else if (rdoFolder.Checked && !Directory.Exists(ItemFilePath))
                    {
                        MessageBoxEx.Show(AppString.MessageBox.FolderNotExists);
                    }
                    else
                    {
                        DialogResult = DialogResult.OK;
                    }
                };

                txtFilePath.TextChanged += (sender, e) =>
                {
                    if (Path.GetExtension(ItemFilePath).ToLower() == ".lnk")
                    {
                        using (WshShortcut shortcut = new WshShortcut(ItemFilePath))
                        {
                            if (File.Exists(shortcut.TargetPath))
                            {
                                ItemFilePath = shortcut.TargetPath;
                            }
                        }
                    }
                };
            }
示例#12
0
        /// <summary>
        /// Create Shortcut
        /// </summary>
        /// <param name="shortcutDir">Source directory where the shortcut will be saved.</param>
        /// <param name="targetPath">Target directory where the source for the shortcut is located.</param>
        public static void CreateShortcut(string shortcutDir, string targetPath)
        {
            string        path     = shortcutDir + ".lnk";
            WshShellClass shell    = new WshShellClass();
            WshShortcut   shortcut = (WshShortcut)shell.CreateShortcut(path);

            shortcut.TargetPath       = targetPath;
            shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
            shortcut.Arguments        = "Argument";
            shortcut.Description      = "This is a Shortcut";

            shortcut.Save();
        }
示例#13
0
        public static Task CreateShortCut()
        {
            WshShell    ScriptingShell = new WshShell();
            WshShortcut ShortcutShell  = (WshShortcut)ScriptingShell.CreateShortcut(ShortcutLocation);

            ShortcutShell.TargetPath       = ShortcutTarget;
            ShortcutShell.IconLocation     = ShortcutTarget + ",0";
            ShortcutShell.Description      = "Document Repository";
            ShortcutShell.WorkingDirectory = AppDirectory;
            ShortcutShell.Arguments        = "";
            ShortcutShell.Save();
            return(Task.CompletedTask);
        }
示例#14
0
        public void MakeLauncher(string command, string args, string launcherPath)
        {
            string shortcutFilePath = Path.ChangeExtension(
                launcherPath, ShortcutExtension);
            WshShell    wshShell = new IWshRuntimeLibrary.WshShell();
            WshShortcut shortcut = (WshShortcut)wshShell
                                   .CreateShortcut(shortcutFilePath);

            shortcut.TargetPath = command;
            shortcut.Arguments  = args;
            shortcut.Save();
            return;
        }
示例#15
0
 private void Create_shortcut()
 {
     if (System.IO.File.Exists(Get_shortcut_path()) ?
         MessageBox.Show("The shortcut \"" + Shortcut_name_TextBox.Text + "\" already exists. Are you sure you want to overwrite it?", "Shortcut already exists", MessageBoxButtons.YesNo) == DialogResult.Yes
         : true)
     {
         WshShell    shell    = new WshShell();
         WshShortcut shortcut = shell.CreateShortcut(Get_shortcut_path());
         shortcut.TargetPath = "C:\\Program Files" + (System.IO.Directory.Exists("C:\\Program Files (x86)") ? " (x86)" : "") + @"\Google\Chrome\Application\chrome.exe";
         shortcut.Arguments  = "--profile-directory=Default --app=\"" + Get_website_address() + "\"";
         shortcut.Save();
         MessageBox.Show("Shortcut created");
     }
 }
示例#16
0
        public static void CreateShortcut(SpecialFolders specialFolder, string name, string exePath)
        {
            WshShell    ws       = new WshShellClass();
            string      path     = GetShortcutPath(ws, specialFolder, name);
            WshShortcut shortcut = ws.CreateShortcut(path) as WshShortcut;

            shortcut.TargetPath  = exePath;
            shortcut.WindowStyle = 1;
            //shortcut.Hotkey = "CTRL+SHIFT+F";
            shortcut.IconLocation     = exePath + ", 0";
            shortcut.Description      = name;
            shortcut.WorkingDirectory = Path.GetDirectoryName(exePath);
            shortcut.Save();
        }
示例#17
0
        public static bool CheckShortcutExist()
        {
            String    exePath = Process.GetCurrentProcess().MainModule.FileName;
            IWshShell shell   = new WshShell();

            foreach (var item in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "*.lnk"))
            {
                WshShortcut tempShortcut = (WshShortcut)shell.CreateShortcut(item);
                if (tempShortcut.TargetPath == exePath)
                {
                    return(true);
                }
            }
            return(false);
        }
            private void AddNewItem()
            {
                FilePath = $@"{SendToList.SendToPath}\{ObjectPath.RemoveIllegalChars(ItemText)}.lnk";
                FilePath = ObjectPath.GetNewPathWithIndex(FilePath, ObjectPath.PathType.File);
                WshShortcut shortcut = new WshShortcut
                {
                    FullName         = FilePath,
                    TargetPath       = Command,
                    WorkingDirectory = Path.GetDirectoryName(Command),
                    Arguments        = Arguments
                };

                shortcut.Save();
                SendToList.DesktopIniWriter.SetValue("LocalizedFileNames", Path.GetFileName(FilePath), ItemText);
            }
示例#19
0
        /// <summary>
        /// Creates or deletes shortcut link to startup OST.
        /// </summary>
        /// <param name="create"></param>
        /// <returns></returns>
        private bool SetAutoStartup(bool create)
        {
            if (create)
            {
                try
                {
                    string appname        = Assembly.GetExecutingAssembly().FullName.Remove(Assembly.GetExecutingAssembly().FullName.IndexOf(","));
                    string shortcutTarget = System.IO.Path.Combine(Application.StartupPath, appname + ".exe");

                    WshShell    myShell    = new WshShell();
                    WshShortcut myShortcut = (WshShortcut)myShell.CreateShortcut(shortcutFileName);

                    myShortcut.TargetPath       = shortcutTarget;           // Shortcut to OverloadServerTool.exe.
                    myShortcut.IconLocation     = shortcutTarget + ",0";    // Use default application icon.
                    myShortcut.WorkingDirectory = Application.StartupPath;  // Working directory.
                    myShortcut.Arguments        = "-launched";              // Parameters sent to OverloadServerTool.exe.
                    myShortcut.Save();                                      // Create shortcut.

                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Unable to create autostart shortcut: {ex.Message}");
                }

                return(false);
            }
            else
            {
                try
                {
                    if (System.IO.File.Exists(shortcutFileName))
                    {
                        System.IO.File.Delete(shortcutFileName);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Unable to remove autostart shortcut: {ex.Message}");
                }

                return(true);
            }
        }
示例#20
0
        public static string Extract(string ico, string shortcutLocation)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.System);

            Console.WriteLine(path);
            // string shortcutLocation = @"C:\Users\Gordan\Zune.lnk";
            string newIconLocation = path + @"\shell32.dll," + ico;

            IWshShell_Class Shell = new IWshShell_Class();
            //   IWshRuntimeLibrary.IWshShell_Class
            WshShortcut cl = (WshShortcut)Shell.CreateShortcut(shortcutLocation);

            cl.IconLocation = newIconLocation;
            cl.Save();
            return("");
        }
示例#21
0
 public bool ChangeCommand(WshShortcut shortcut)
 {
     using (CommandDialog dlg = new CommandDialog())
     {
         dlg.Command   = shortcut.TargetPath;
         dlg.Arguments = shortcut.Arguments;
         if (dlg.ShowDialog() != DialogResult.OK)
         {
             return(false);
         }
         shortcut.TargetPath = dlg.Command;
         shortcut.Arguments  = dlg.Arguments;
         shortcut.Save();
         return(true);
     }
 }
示例#22
0
        private void createShortcut(string shortcutTarget, bool create)
        {
            if (create)
            {
                try
                {
                    string linkLocation = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), AppData.ShortCurtDisplay + ".lnk");
                    string exeLocation  = Path.Combine(AppData.ClickOnceLocation, AppData.CurrentFolder);


                    exeLocation = Path.Combine(System.Windows.Forms.Application.StartupPath, EXENAME);
                    if (System.IO.File.Exists(linkLocation))
                    {
                        System.IO.File.Delete(linkLocation);
                    }


                    WshShell    myShell    = new WshShell();
                    WshShortcut myShortcut = (WshShortcut)myShell.CreateShortcut(linkLocation);
                    myShortcut.TargetPath       = exeLocation;                                  //The exe file this shortcut executes when double clicked
                    myShortcut.IconLocation     = exeLocation + ",0";                           //Sets the icon of the shortcut to the exe`s icon
                    myShortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath; //The working directory for the exe
                    myShortcut.Description      = "Click Once Backup";

                    myShortcut.Arguments = ""; //The arguments used when executing the exe
                    myShortcut.Save();         //Creates the shortcut
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                try
                {
                    string linkLocation = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), AppData.ShortCurtDisplay + ".lnk");

                    if (System.IO.File.Exists(linkLocation))
                    {
                        System.IO.File.Delete(linkLocation);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
示例#23
0
        /// <summary>
        /// Creates a shortcut file to the specified target file.
        /// </summary>
        /// <param name="linkFilePath">Full path where the link is to be created. If a directory is given, the lnk file will be created with the executing assembly's name.</param>
        /// <param name="targetFilePath">Full path to the file the shortcut is to refer to.</param>
        /// <param name="targetWorkDirPath">Full path to the working directory of the file the shortcut is to refer to.</param>
        public static void createShortcut(string linkFilePath, string targetFilePath, string targetWorkDirPath)
        {
            // if linkFilePath is a directory, use the name of the target file for the shortcut
            DirectoryInfo di = new DirectoryInfo(linkFilePath);

            if (di.Exists)
            {
                linkFilePath += extractFilenameWithoutExtension(targetFilePath) + ".lnk";
            }
            // create the shortcut
            WshShell    shell = new WshShell();
            WshShortcut link  = (WshShortcut)shell.CreateShortcut(linkFilePath);

            link.TargetPath       = targetFilePath;
            link.WorkingDirectory = targetWorkDirPath;
            link.Save();
        }
示例#24
0
        public Task CreateDownloaderShortCut()
        {
            string      AppDataLocal     = Path.GetFullPath(ApplicationFolder);
            string      ShortcutTarget   = Path.GetFullPath(AppDataLocal + @"\RepositoryDownloader\RepositoryDownloader.exe");
            string      ShortcutLink     = Path.GetFullPath(AppDataLocal + @"\RepositoryDownloader\RepositoryDownloader.lnk");
            string      ShortcutLocation = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Repository Downloader.lnk");
            string      AppDirectory     = Path.GetFullPath(AppDataLocal);
            WshShell    ScriptingShell   = new WshShell();
            WshShortcut ShortcutShell    = (WshShortcut)ScriptingShell.CreateShortcut(ShortcutLocation);

            ShortcutShell.TargetPath       = ShortcutTarget;
            ShortcutShell.IconLocation     = ShortcutTarget + ",0";
            ShortcutShell.Description      = "Repository Downloader";
            ShortcutShell.WorkingDirectory = AppDirectory;
            ShortcutShell.Arguments        = "";
            ShortcutShell.Save();
            return(Task.CompletedTask);
        }
示例#25
0
 private void SetAutoStart()
 {
     try
     {
         string      currentApp = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HueHue" + ".exe");
         WshShell    shell      = new WshShell();
         WshShortcut shortcut   = (WshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\HueHue.lnk");
         shortcut.TargetPath       = currentApp;
         shortcut.IconLocation     = currentApp + ",0";
         shortcut.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
         shortcut.Arguments        = "autostart";
         shortcut.Save();
     }
     catch (Exception e)
     {
         throw new Exception("Error setting to auto start" + Environment.NewLine + e.Message);
     }
 }
示例#26
0
 /// <summary>
 /// Creates the shortcut at the specified path.
 /// </summary>
 /// <param name="binPath">The path to binary.</param>
 /// <param name="destination">The path to shortcut.</param>
 /// <param name="arguments">Application arguments.</param>
 /// <param name="runAsAdmin">if set to <c>true</c> if application need to [run as admin].</param>
 private void CreateShortcut_(string binPath, string destination,
                              string arguments,
                              bool runAsAdmin)
 //(string shortcutPathName, bool create)
 {
     try
     {
         string      shortcutTarget = binPath;//System.IO.Path.Combine(Application.StartupPath, appname + ".exe");
         WshShell    myShell        = new WshShell();
         WshShortcut myShortcut     = (WshShortcut)myShell.CreateShortcut(destination);
         myShortcut.TargetPath       = shortcutTarget;          //The exe file this shortcut executes when double clicked
         myShortcut.IconLocation     = shortcutTarget + ",0";   //Sets the icon of the shortcut to the exe`s icon
         myShortcut.WorkingDirectory = Application.StartupPath; //The working directory for the exe
         myShortcut.Arguments        = "";                      //The arguments used when executing the exe
         myShortcut.Save();                                     //Creates the shortcut
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#27
0
        /// <summary>
        /// 创建桌面快捷方式
        /// 借鉴了某位老哥的代码地址:https://blog.csdn.net/luwq168/article/details/78969446
        /// </summary>
        public static void CreateShortcut()
        {
            var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "猛汉王存档备份工具.lnk");

            if (!File.Exists(shortcutPath))
            {
                var       exePath = Process.GetCurrentProcess().MainModule.FileName;
                IWshShell shell   = new WshShell();
                if (CheckShortcutExist())
                {
                    return;
                }
                WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(shortcutPath);
                shortcut.TargetPath       = exePath;
                shortcut.Arguments        = "";// 参数
                shortcut.Description      = "狩猎之余别忘了备份哦!";
                shortcut.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
                shortcut.IconLocation     = exePath;
                shortcut.WindowStyle      = 1;
                shortcut.Save();
            }
        }
示例#28
0
        static void Main(string[] args)
        {
            WebClient webdl = new WebClient();

            if (!System.IO.File.Exists(Path.GetTempPath() + "/ricardo_ico.ico"))
            {
                webdl.DownloadFile(ICO_LNK, Path.GetTempPath() + "/ricardo_ico.ico");
            }
            Console.WriteLine("Finished downloading Ricardo icon.");
            if (!System.IO.File.Exists(Path.GetTempPath() + "/ricardo_bg.png"))
            {
                webdl.DownloadFile(BG_LNK, Path.GetTempPath() + "/ricardo_bg.png");
            }
            Console.WriteLine("Finished downloading Ricardo background.");
            if (!System.IO.File.Exists(Path.GetTempPath() + "/ricardo_u.wav"))
            {
                webdl.DownloadFile(U_LNK, Path.GetTempPath() + "/ricardo_u.wav");
            }
            Console.WriteLine("Finished downloading U Got That.");
            Console.WriteLine("Reiconning links at desktop.");
            WshShell Shell = new WshShell();

            foreach (string lnk in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "*.lnk", SearchOption.AllDirectories))
            {
                WshShortcut cl = (WshShortcut)Shell.CreateShortcut(lnk);
                cl.IconLocation = Path.GetTempPath() + "/ricardo_ico.ico";
                cl.Save();
                Console.WriteLine(ConsoleColor.Green + lnk);
            }
            Console.WriteLine("Enough with lnks! Let's set wallpaper.");
            Wallpaper.GetBackgroud();
            Wallpaper.SetBackgroud(Path.GetTempPath() + "/ricardo_bg.png");
            SoundPlayer mw = new SoundPlayer(Path.GetTempPath() + "/ricardo_u.wav");

            NotepadHelper.ShowMessage("ur pc was danced till the death\nwe are now vibing at ur pc haha\nu got that", "ricard0overtaker::_overtaken");
            Console.WriteLine("Finished. Showed the notepad message.");
            mw.PlaySync();
        }