Exemple #1
0
        /// <summary>
        /// SendTo Command
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSendTo_Click(object sender, EventArgs e)
        {
            string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.SendTo);
            string link = string.Format(@"{0}\{1}.lnk", path, this.Text);

            if (!SendToFlag)
            {
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                IWshRuntimeLibrary.IWshShortcut SendTo = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(link);

                SendTo.TargetPath       = this.GetType().Assembly.Location;
                SendTo.Arguments        = "";
                SendTo.Description      = "Windows系统快捷方法创建工具";
                SendTo.WorkingDirectory = System.Environment.CurrentDirectory;
                SendTo.IconLocation     = string.Format("{0},0", this.GetType().Assembly.Location);
                SendTo.Hotkey           = "CTRL+S";
                SendTo.WindowStyle      = 1;
                SendTo.Save();
                Msg("删除\"发送到\"命令完成", MSG_TYPE.ERROR);
            }
            else
            {
                System.IO.File.Delete(link);
                Msg("删除\"发送到\"命令完成", MSG_TYPE.GREEN);
            }
            GetSendToButtonStatus();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            pathStringBuilder path = new pathStringBuilder();

            //Console.WriteLine(path.BuildFullPath());
            //Console.WriteLine(path.BuildFolderName());
            Console.WriteLine(path.BuildDesktopShortcutPath());

            //Console.ReadKey();
            //Comment in the below for production
            //Directory.CreateDirectory(path.BuildFullPath());



            void CreateShortcut(string linkPath, string filename)
            {
                // Create shortcut dir if not exists
                if (!Directory.Exists(linkPath))
                {
                    Directory.CreateDirectory(linkPath);
                }

                // COM object instance/props
                IWshRuntimeLibrary.WshShell     shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut sc    = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filename);
                sc.Description = "Shortcut to today's shortcut folder.";
                //shortcut.IconLocation = @"C:\...";
                sc.TargetPath = linkPath;//ADAM:---------------this needs to be the path to the folder
                // save shortcut to target
                sc.Save();
            }

            CreateShortcut(path.BuildFullPath(), path.BuildDesktopShortcutPath());
        }
Exemple #3
0
        /// <summary>
        /// Create Windows Shorcut
        /// </summary>
        /// <param name="SourceFile">A file you want to make shortcut to</param>
        /// <param name="ShortcutFile">Path and shorcut file name including file extension (.lnk)</param>
        /// <param name="Description">Shortcut description</param>
        /// <param name="Arguments">Command line arguments</param>
        /// <param name="HotKey">Shortcut hot key as a string, for example "Ctrl+F"</param>
        /// <param name="WorkingDirectory">"Start in" shorcut parameter</param>
        public static void CreateShortcut(string SourceFile, string arguments, string ShortcutFile)
        {
            // Check necessary parameters first:
            if (String.IsNullOrEmpty(SourceFile))
            {
                throw new ArgumentNullException("SourceFile");
            }
            if (String.IsNullOrEmpty(ShortcutFile))
            {
                throw new ArgumentNullException("ShortcutFile");
            }

            // Create WshShellClass instance:
            IWshShell3 wshShell = new WshShellClass();

            // Create shortcut object:
            IWshRuntimeLibrary.IWshShortcut shorcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(ShortcutFile);

            shorcut.Arguments = arguments;

            // Assign shortcut properties:
            shorcut.TargetPath = SourceFile;

            // Save the shortcut:
            shorcut.Save();
        }
Exemple #4
0
        public static void CreateLink(string shortcutFullPath, string target)
        {
            WshShell wshShell = new WshShell();

            IWshRuntimeLibrary.IWshShortcut newShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutFullPath);
            newShortcut.TargetPath = target;
            newShortcut.Save();
        }
Exemple #5
0
        static void Shortcut(String source, String dest, String description = "")
        {
            WshShell wsh = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(dest);
            shortcut.Arguments  = ".";
            shortcut.TargetPath = source;

            shortcut.Save();
        }
 protected override void ProcessRecord()
 {
     if (_linkPath != null)
     {
         try
         {
             WriteVerbose(_cmdlet + ": Starting with" + _linkPath + ".");
             if (System.IO.File.Exists(_linkPath))
             {
                 try
                 {
                     if (this.ShouldProcess(_linkPath, "SetShortcut"))
                     {
                         WshShellClass wshShell = new WshShellClass();
                         IWshRuntimeLibrary.IWshShortcut lnk = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(_linkPath);  // depends on this openening the existing shortcut!
                         string savetarget = lnk.TargetPath;
                         WriteVerbose(_cmdlet + ": Original targetpath " + Statics.StaticClass.DoubleQuoteMe(savetarget));
                         lnk.TargetPath = "C:\\Windows\\System32\\reg.exe";
                         lnk.Arguments  = "/import " + savetarget + " " + lnk.Arguments;
                         lnk.Save();
                         output     += _cmdlet + ": SUCCESS Shortcut \"" + _linkPath + "\" updated.\n";
                         needRefresh = true;
                     }
                     else
                     {
                         output += _cmdlet + ":  Shortcut \"" + _linkPath + "\" would have been updated.\n";
                     }
                 }
                 catch (Exception ex)
                 {
                     output += _cmdlet + ": ERROR Editing \"" + _linkPath + "\" " + ex.Message + "\n";
                 }
             }
             else
             {
                 output += _cmdlet + ": ERROR File \"" + _linkPath + "\" Does not exist.\n";
             }
         }
         catch (Exception ex)
         {
             output += _cmdlet + ": ERROR Editing \"" + _linkPath + "\" " + ex.Message + "\n";
         }
     }
     else
     {
         output += _cmdlet + ": ERROR Missing required parameter.\n";
     }
     WriteObject(output);
     if (needRefresh)
     {
         SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
     }
 }
Exemple #7
0
        public static void place_shortcut_on_desktop()
        {
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\YourName.lnk";
            string shortcutto  = System.Reflection.Assembly.GetExecutingAssembly().Location;

            var wsh = new IWshShell_Class();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(desktopPath) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.TargetPath       = shortcutto;
            shortcut.WorkingDirectory = Directory.GetParent(shortcutto).FullName;
            shortcut.Save();
        }
        private void AddShortcut(string shortCutPath)
        {
            shellLib.WshShell shell = new shellLib.WshShell();

            string shortcutPath = shortCutPath;

            shellLib.IWshShortcut shortcut = (shellLib.IWshShortcut)shell.CreateShortcut(shortcutPath);
            shortcut.Description = "Ярлык для терминала CTC";
            //string terminalDir = Environment.GetEnvironmentVariable("TERMINAL_PATH");
            shortcut.TargetPath = PathTerminalExecDir + @"\Terminal.exe";  //Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";

            shortcut.Save();
        }
Exemple #9
0
        /// <summary>
        /// Used to add the program into startup list
        /// </summary>
        public static void AddToStartup()
        {
            var startupDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\";

            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                startupDir + "\\" + ShortcutFileName) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.TargetPath       = System.Reflection.Assembly.GetEntryAssembly().Location;
            shortcut.WindowStyle      = 1;
            shortcut.Description      = ShortcutFileDescription;
            shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(shortcut.TargetPath);
            shortcut.Save();
        }
Exemple #10
0
        public void CreateIcon()
        {
            string dt = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            dt += "\\ScreenSnip.lnk";

            string shortcutLocation = dt;

            WSH.WshShell     shell    = new WSH.WshShell();
            WSH.IWshShortcut shortcut = (WSH.IWshShortcut)shell.CreateShortcut(shortcutLocation);
            shortcut.Description = "WolfPaw Screen Snipper tool";
            shortcut.TargetPath  = Properties.Settings.Default.s_Path + "\\WolfPaw ScreenSnip.exe";
            shortcut.Save();
        }
Exemple #11
0
        public static void changeAllShortcuts()
        {
            string[] files    = System.IO.Directory.GetFiles(Paths.ShortcutsPath, "*.lnk");
            WshShell wshShell = new WshShell();

            foreach (string filePath in files)
            {
                IWshRuntimeLibrary.IWshShortcut newShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(filePath);
                newShortcut.TargetPath       = Paths.BackgroundApplication;
                newShortcut.IconLocation     = Path.Combine(Paths.ConfigPath, newShortcut.Arguments.Trim(), "GroupIcon.ico");
                newShortcut.WorkingDirectory = Path.Combine(Paths.ConfigPath, newShortcut.Arguments.Trim());
                newShortcut.Save();
            }
        }
Exemple #12
0
        public void CreateShortcutFile(string appPath, string appName, string destinationPath)
        {
            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(destinationPath
                                                                          + "\\Ung Dung Hoc Tu.lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments  = "";
            shortcut.TargetPath = appPath + appName;
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Ứng Dụng Học Từ";
            shortcut.WorkingDirectory = appPath;
            shortcut.IconLocation     = appPath + "/Resources/appicon.ico";
            shortcut.Save();
        }
Exemple #13
0
        private static void CreateShortcut(string sdvFolder, string name, string logName, int playerIndex)
        {
            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                Path.Combine(sdvFolder, $"{name}.lnk")) as IWshRuntimeLibrary.IWshShortcut;

            shortcut.Arguments        = $" --log-path \"{logName}.txt\" --player-index {playerIndex}";
            shortcut.TargetPath       = Path.Combine(sdvFolder, "StardewModdingAPI.exe");
            shortcut.WindowStyle      = 1;
            shortcut.Description      = name;
            shortcut.WorkingDirectory = sdvFolder;
            //shortcut.IconLocation = "specify icon location";
            shortcut.Save();
        }
Exemple #14
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (li == 1)
            {
                if (Directory.Exists(drive + @"\\App"))
                {
                    ZipFile.ExtractToDirectory("config\\data\\install\\install.App", drive + "\\App\\");
                    System.Diagnostics.Process.Start(drive + "\\App\\" + sc + "\\" + sc1 + ".exe");
                    string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹
                    IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();



                    IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\" + sc1 + ".lnk");
                    shortcut.TargetPath       = drive + "\\App\\" + sc + "\\" + sc1 + ".exe";
                    shortcut.Arguments        = "";                                                  // 参数
                    shortcut.Description      = "Applications";
                    shortcut.WorkingDirectory = drive + "\\App\\" + sc;                              //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
                    shortcut.IconLocation     = drive + "\\App\\" + sc + "\\" + sc1 + ".exe" + ",0"; //图标
                    shortcut.Hotkey           = "";                                                  //热键
                    shortcut.WindowStyle      = 1;
                    shortcut.Save();

                    shortcut.Save();//保存快捷方式
                    MessageBox.Show("安装成功", "Done 完成");
                }
                else
                {
                    Directory.CreateDirectory(drive + @"\\App");
                }
                li = 0;
            }
            else
            {
            }
        }
Exemple #15
0
        /// <summary>
        /// Creates executable shortcut to the mod
        /// </summary>
        public void CreateExe()
        {
            string path      = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            object shDesktop = (object)"Desktop";

            wsh.WshShell shell           = new wsh.WshShell();
            string       shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Ucieczka.lnk";

            wsh.IWshShortcut shortcut = (wsh.IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.Description  = "Uruchom modyfikację G2 Ucieczka";
            shortcut.TargetPath   = window.GothicPath + @"\System\Gothic2.exe";
            shortcut.IconLocation = window.GothicPath + @"\System\Ucieczka.ico";
            shortcut.Arguments    = "-game:Ucieczka.ini";
            shortcut.Save();
        }
Exemple #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            WshShellClass wsh = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\" + textBox1.Text + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments  = "";
            shortcut.TargetPath = System.IO.Path.GetFullPath(openFileDialog1.FileName);
            // not sure about what this is for
            shortcut.WindowStyle = 10;
            shortcut.Description = "Create customized Run command";
            //shortcut.WorkingDirectory = "C:\\TURBOC3\\Turbo C++\\";
            //shortcut.IconLocation = "RunCustomizer.ico";
            shortcut.Save();
        }
Exemple #17
0
        static void Main(string[] args)
        {
            string sourcePath = Directory.GetCurrentDirectory() + @"\InstallationFiles\";
            string targetPath = @"C:\ZipPassword";

            string[] files    = System.IO.Directory.GetFiles(sourcePath);
            string   fileName = "";

            try
            {
                if (!System.IO.Directory.Exists(targetPath))
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                    foreach (string s in files)
                    {
                        fileName = System.IO.Path.GetFileName(s);
                        System.IO.File.Copy(s, System.IO.Path.Combine(targetPath + @"\", fileName), true);
                    }
                }
                if (System.IO.Directory.Exists(targetPath))
                {
                    foreach (string s in files)
                    {
                        fileName = System.IO.Path.GetFileName(s);
                        System.IO.File.Copy(s, System.IO.Path.Combine(targetPath + @"\", fileName), true);
                    }
                }

                WshShell wsh = new WshShell();
                IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\ZipPassword.lnk") as IWshRuntimeLibrary.IWshShortcut;
                shortcut.Arguments        = "";
                shortcut.TargetPath       = targetPath + @"\ZipPassword.exe";
                shortcut.WindowStyle      = 1;
                shortcut.WorkingDirectory = targetPath;
                shortcut.IconLocation     = targetPath + @"\ico_password.ico";
                shortcut.Save();
                Console.WriteLine(string.Format(@"Pliki instalacyjne znajdują się na dysku C:\ w lokalizacji {0} ."
                                                + Environment.NewLine +
                                                @"Skrót do aplikacji został utworzony na pulpicie."
                                                + Environment.NewLine +
                                                @"Pozdrawiam, Łukasz D.", targetPath));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Thread.Sleep(10000);
        }
Exemple #18
0
        public static void AppShortcutToDesktop()         //Creates a shortcut to the desktop.
        {
            string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Scoring Report.lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments        = "";
            shortcut.TargetPath       = "C:\\Dynamix\\score_report.html";
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Windows Scoring Report";
            shortcut.WorkingDirectory = "c:\\Dynamix";
            shortcut.IconLocation     = "C:\\Dynamix\\dx-128-icon.ico";
            shortcut.Save();
        }
Exemple #19
0
        private void CreateShotcut(string newPackageName)
        {
            string        path = Application.StartupPath;
            WshShellClass wsh  = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + newPackageName + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments = "\"" + newPackageName + "\"";

            shortcut.TargetPath = path + "\\CDT.exe";
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = newPackageName;
            shortcut.WorkingDirectory = path;
            shortcut.Save();
        }
Exemple #20
0
        public void CreateShortcut(string shortcutName, string shortcutPath, string shortcutDescription, string directory, string shortcutArguments)
        {
            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + shortcutName + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments  = shortcutArguments;
            shortcut.TargetPath = shortcutPath; // c:\\app\\myftp.exe
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = shortcutDescription; // my shortcut description
            shortcut.WorkingDirectory = directory;           // c:\\app
            // shortcut.IconLocation = "specify icon location"; // specify icon location
            shortcut.Save();
            loadingLog.Text += "Snarvei til " + shortcutName + "\r\n";
        }
Exemple #21
0
        public static void CreateDesktopLnk(string AppPath)
        {
            string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹

            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\GBT.lnk");
            shortcut.TargetPath       = AppPath + "GBT.exe";
            shortcut.Arguments        = "";                                  //参数
            shortcut.Description      = "http://gamelab.1111";
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
            shortcut.IconLocation     = AppPath + "GBT.exe,0";               //图标
            shortcut.Hotkey           = "";                                  //热键
            shortcut.WindowStyle      = 1;
            shortcut.Save();
        }
Exemple #22
0
        /// <summary>
        /// Create Windows Shorcut
        /// </summary>
        /// <param name="SourceFile">A file you want to make shortcut to</param>
        /// <param name="ShortcutFile">Path and shorcut file name including file extension (.lnk)</param>
        /// <param name="Description">Shortcut description</param>
        /// <param name="Arguments">Command line arguments</param>
        /// <param name="HotKey">Shortcut hot key as a string, for example "Ctrl+F"</param>
        /// <param name="WorkingDirectory">"Start in" shorcut parameter</param>
        public static void CreateShortcut(string TargetPath, string ShortcutFile, string Description,
                                          string Arguments, string HotKey, string WorkingDirectory, int logo)
        {
            // Check necessary parameters first:
            if (String.IsNullOrEmpty(TargetPath))
            {
                throw new ArgumentNullException("TargetPath");
            }
            if (String.IsNullOrEmpty(ShortcutFile))
            {
                throw new ArgumentNullException("ShortcutFile");
            }

            // Create WshShellClass instance:
            var wshShell = new WshShell();

            // Create shortcut object:
            IWshRuntimeLibrary.IWshShortcut shorcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(ShortcutFile);

            if (logo == 1)
            {
                shorcut.IconLocation = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Iwit Systems\\iwit sync\\dossier-iwit.ico";
            }
            else if (logo == 2)
            {
                shorcut.IconLocation = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\Iwit Systems\\iwit sync\\dossier-iwit.ico";
            }

            // Assign shortcut properties:
            shorcut.TargetPath  = TargetPath;
            shorcut.Description = Description;
            if (!String.IsNullOrEmpty(Arguments))
            {
                shorcut.Arguments = Arguments;
            }
            if (!String.IsNullOrEmpty(HotKey))
            {
                shorcut.Hotkey = HotKey;
            }
            if (!String.IsNullOrEmpty(WorkingDirectory))
            {
                shorcut.WorkingDirectory = WorkingDirectory;
            }

            // Save the shortcut:
            shorcut.Save();
        }
Exemple #23
0
        public void CreateConfig(Image groupImage)
        {
            string path     = @"config\" + this.Name;
            string filePath = path + @"\" + this.Name + "Group.exe";

            //
            // Directory and .exe
            //
            System.IO.Directory.CreateDirectory(@"Shortcuts\");
            System.IO.Directory.CreateDirectory(@path);
            System.IO.File.Copy(@"config\config.exe", @filePath);
            //
            // XML config
            //
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Category));

            using (FileStream file = System.IO.File.Create(@path + @"\ObjectData.xml"))
                writer.Serialize(file, this);
            //
            // Create .ico
            //

            Image img = ImageFunctions.ResizeImage(groupImage, 1024, 1024); // Resize img if too big

            img.Save(path + @"\GroupImage.png");

            using (FileStream fs = new FileStream(path + @"\GroupIcon.ico", FileMode.Create))
                ImageFunctions.IconFromImage(img).Save(fs);  // saving as icon
                                                             //
                                                             // Create .lnk shortcut
                                                             //
            var wsh = new IWshShell_Class();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                path + "\\" + this.Name + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments        = "";
            shortcut.TargetPath       = Path.GetFullPath(@filePath);
            shortcut.WindowStyle      = 1;
            shortcut.Description      = path + " shortcut";
            shortcut.WorkingDirectory = Path.GetFullPath(@path);
            shortcut.IconLocation     = Path.GetFullPath(path + @"\GroupIcon.ico");
            shortcut.Save();
            System.IO.File.Move(@path + "\\" + this.Name + ".lnk",
                                Path.GetFullPath(@"Shortcuts\" + this.Name + ".lnk")); // moving .lnk to correct directory
        }
        private static void updateDeskTopShortCutDescription(string shortcutName)
        {
            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + shortcutName + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            //shortcut.Arguments = "";
            //shortcut.TargetPath = "c:\\app\\myftp.exe";

            string curVersion = ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString() // retourne la bonne version en exécution
                                : Assembly.GetExecutingAssembly().GetName().Version.ToString();                                             //le 2e retourne : 1.0.0.0

            shortcut.Description = "XLApp, Version " + DateTime.Now.Year % 100 + "." + curVersion;
            //shortcut.WorkingDirectory = "c:\\app";
            //shortcut.IconLocation = "specify icon location";
            shortcut.Save();
        }
Exemple #25
0
        private void CreateShortcut(string linkname)
        {
            if (!Directory.Exists(installPath + "\\Resources\\shortcuts"))
            {
                System.IO.Directory.CreateDirectory(installPath + "\\Resources\\shortcuts");
            }
            WshShell wsh = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                installPath + "\\Resources\\shortcuts" + "\\" + EditTitle.Text + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments        = "";
            shortcut.TargetPath       = linkname;
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Shortcut to " + EditTitle.Text;
            shortcut.WorkingDirectory = "C:\\App";
            shortcut.IconLocation     = linkname;
            shortcut.Save();
        }
Exemple #26
0
        /// <summary>
        /// Create Shortcut and copy it to desktop
        /// </summary>
        public static void CreateShortcut()
        {
            var      exePath  = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var      iconPath = $@"{System.IO.Path.GetDirectoryName(exePath)}\resources\forceSync.ico";
            var      deskDir  = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var      linkPath = $@"{deskDir}\OnedriveForceSync.lnk";
            WshShell wsh      = new WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(linkPath) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments  = "--nogui";
            shortcut.TargetPath = exePath;
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Force Sync";
            shortcut.WorkingDirectory = System.IO.Path.GetFullPath(exePath);
            shortcut.IconLocation     = iconPath;
            shortcut.Save();
        }
        public static void RegistyCheck()
        {
            var fullName = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var thisPath = Directory.GetCurrentDirectory();
            //var iconPath = Path.Combine(thisPath, "Note.ico");
            var iconPathReg = "\"" + fullName + "\"" + "";
            var exePathReg  = "\"" + fullName + "\"" + " \"%1\"";
            var exePathReg2 = "\"" + fullName + "\"" + " \"%V\"";

            //File
            Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Long Path Tool", "Icon", iconPathReg, RegistryValueKind.String);
            Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Long Path Tool\command", "", exePathReg, RegistryValueKind.String);
            //Folder
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Long Path Tool", "Icon", iconPathReg, RegistryValueKind.String);
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Long Path Tool\command", "", exePathReg, RegistryValueKind.String);
            //Inside folder
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Long Path Tool", "Icon", iconPathReg, RegistryValueKind.String);
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Long Path Tool\command", "", exePathReg2, RegistryValueKind.String);

            var schPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\SendTo\Long Path Tool.lnk";

            //MessageBox.Show(fullName);
            //MessageBox.Show(thisPath);
            //MessageBox.Show(schPath);
            //MessageBox.Show(fullName);
            if (System.IO.File.Exists(schPath))
            {
                System.IO.File.Delete(schPath);
            }
            WshShellClass wsh = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(schPath) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments  = "";
            shortcut.TargetPath = fullName;
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Long Path Tool";
            shortcut.WorkingDirectory = thisPath;
            shortcut.IconLocation     = fullName;
            shortcut.Save();
            MessageBox.Show("Success Install", "Success Install", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #28
0
        /// <summary>
        /// Creates a link of the currFile in the start menu
        /// </summary>
        /// <param name="currFile"></param>
        private void createShortcut(string currFile, string iconLocation, string iconName)
        {
            string startMenuDir = Context.Parameters["StartMenuDir"];
            //throw new Exception("startMenuDir = " + startMenuDir + " currFile = " + currFile + " iconLocation = " + iconLocation);
            string        shortcutName = startMenuDir + "\\" + Path.GetFileName(currFile) + ".lnk";
            WshShellClass WshShell     = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@shortcutName);
            shortcut.TargetPath  = @currFile;
            shortcut.Description = "Open " + Path.GetFileName(currFile);
            if ((iconLocation != null) && (iconName != null))
            {
                if (!iconName.StartsWith("\\"))
                {
                    iconName = "\\" + iconName;
                }
                shortcut.IconLocation = iconLocation + @iconName;
            }
            shortcut.Save();
        }
Exemple #29
0
        /// <summary>
        /// Create Windows Shorcut
        /// </summary>
        /// <param name="SourceFile">A file you want to make shortcut to</param>
        /// <param name="ShortcutFile">Path and shorcut file name including file extension (.lnk)</param>
        /// <param name="Description">Shortcut description</param>
        /// <param name="Arguments">Command line arguments</param>
        /// <param name="HotKey">Shortcut hot key as a string, for example "Ctrl+F"</param>
        /// <param name="WorkingDirectory">"Start in" shorcut parameter</param>
        public static void CreateShortcut(string SourceFile, string ShortcutFile, string Description,
                                          string Arguments, string HotKey, string WorkingDirectory)
        {
            // Check necessary parameters first:
            if (String.IsNullOrEmpty(SourceFile))
            {
                throw new ArgumentNullException("SourceFile");
            }
            if (String.IsNullOrEmpty(ShortcutFile))
            {
                throw new ArgumentNullException("ShortcutFile");
            }

            // Create WshShellClass instance:
            WshShell wshShell = new WshShell();

            // Create shortcut object:
            IWshRuntimeLibrary.IWshShortcut shorcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(ShortcutFile);

            // Assign shortcut properties:
            shorcut.TargetPath   = SourceFile;
            shorcut.Description  = Description;
            shorcut.IconLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\icons\256x256.ico");

            if (!String.IsNullOrEmpty(Arguments))
            {
                shorcut.Arguments = Arguments;
            }
            if (!String.IsNullOrEmpty(HotKey))
            {
                shorcut.Hotkey = HotKey;
            }
            if (!String.IsNullOrEmpty(WorkingDirectory))
            {
                shorcut.WorkingDirectory = WorkingDirectory;
            }

            // Save the shortcut:
            shorcut.Save();
        }
Exemple #30
0
        private void Form1_Load(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("manulife.exe");

            bool b = System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + "manulife Automatic.lnk");

            if (!b)
            {
                string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹
                IWshRuntimeLibrary.WshShell     shell    = new WshShell();
                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\manulife Automatic.lnk");
                shortcut.TargetPath       = File_ + "/manulife.exe";
                shortcut.Arguments        = "";// 参数
                shortcut.Description      = "manulife";
                shortcut.WorkingDirectory = File_;
                shortcut.IconLocation     = File_ + "/manulife,0";//图标
                shortcut.WindowStyle      = 1;
                shortcut.Save();
            }

            this.Close();
        }