示例#1
0
 public static void CreateDesktopShortcut(string shortcutName, string description, string exePath)
 {
     WshShell shell = new WshShell();
     object shDesktop = (object)"Desktop";
     string shortcutPath = (string)shell.SpecialFolders.Item(ref shDesktop);
     CreateShortcut(shortcutName, description, exePath, shortcutPath);
 }
示例#2
0
 public bool Disattach(FileInfo fc) {
     var files = StartupFolder.GetFiles();
     IWshShell shell = new WshShell();
     foreach (var shortcut in files.Where(f=>f.Extension.Contains("lnk"))) {
         IWshShortcut p;
         try {
             p = shell.CreateShortcut(shortcut.FullName) as IWshShortcut;
         } catch (COMException) {
             continue;
         }
         
         if (p == null) continue;
         FileInfo @out;
         try {
             @out = new FileInfo(p.TargetPath);
         } catch {
             continue;
         }
         if (p.TargetPath.Equals(fc.FullName)) {
             try {
                 shortcut.Delete();
             } catch {
                 return false;
             }
             return true;
         }
     }
     return true;
 }
示例#3
0
        public static bool CreateUserProfileShortcut(string userProfileName, DirectoryInfo shortcutDir, string shortcutName)
        {
            var isCreated = false;

            var shell = new WshShell();

            try
            {
                var link = (IWshShortcut)shell.CreateShortcut(shortcutDir.FullName + "\\" + shortcutName + "." + SystemDetails.WinShortcutFileExt);
                link.TargetPath = SystemDetails.ChromeExeFile.FullName;
                if (!SystemDetails.IsDefaultProfile(userProfileName))
                {
                    link.Arguments = SystemDetails.ChromeExeArgId + SystemDetails.ChromeUserDataDirArg + "=\"" +
                                     SystemDetails.ChromeUserDataDir + "\\" + userProfileName + "\"";
                }
                link.WorkingDirectory = SystemDetails.ChromeAppDir.FullName;
                link.Save();

                isCreated = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return isCreated;
        }
        public static GamePath CreateShortcutPath(string path, string arguments)
        {
            string workingDirectory = null;
            try
            {
                IWshShell ws = new WshShell();
                IWshShortcut sc = (IWshShortcut)ws.CreateShortcut(path);
                Logger.LogDebug("\r\n\tShortcut target path: {0}\r\n\tShortcut arguments: {1}\r\n\tShortcut working directory: {2}", sc.TargetPath, sc.Arguments, sc.WorkingDirectory);
                if (!string.IsNullOrEmpty(sc.TargetPath))
                    path = sc.TargetPath;
                if (string.IsNullOrEmpty(arguments))
                    arguments = sc.Arguments;
                workingDirectory = sc.WorkingDirectory;
            }
            catch (Exception ex)
            {
                Logger.LogError("GamePathBuilder: Error reading shortcut {0} - {1}", path, ex.Message);
            }

            return new GamePath()
            {
                Path = path,
                Arguments = arguments,
                WorkingDirectory = workingDirectory
            };
        }
示例#5
0
		/// <summary>Creates a user defined shortcut.</summary>
		public void CreateShortcut(CsgLnkShortcut shortcut)
		{
			if (String.IsNullOrEmpty(shortcut.DestinationDirectory))
				throw new ArgumentException("a destination have to be defined.");
			if (!File.Exists(shortcut.SourceFile))
				throw new FileNotFoundException();
			if (!File.Exists(shortcut.SourceIconFile))
				throw new FileNotFoundException();
			if (String.IsNullOrEmpty(shortcut.Name))
				throw new ArgumentException();

			var sourceDirectory = (new FileInfo(shortcut.SourceFile)).Directory;
			if (sourceDirectory == null)
				throw new DirectoryNotFoundException();


			var wsh = new WshShell();
			var sc = (IWshShortcut) wsh.CreateShortcut(Path.Combine(shortcut.DestinationDirectory, shortcut.Name + ".lnk"));

			sc.TargetPath = shortcut.SourceFile;
			sc.WorkingDirectory = sourceDirectory.FullName;
			sc.IconLocation = shortcut.SourceIconFile;
			sc.Description = shortcut.Description;
			sc.WindowStyle = 1;
			sc.Save();
		}
 public static string GetShortcutTargetFile(string path)
 {
     if (!File.Exists(path))
         return path;
     var shell = new WshShell();
     var link = (IWshShortcut) shell.CreateShortcut(path);
     return File.Exists(link.TargetPath) ? link.TargetPath : path;
 }
示例#7
0
 public static void CreateShortcut(string shortcutName, string description, string exePath, string shortcutPath)
 {
     WshShell shell = new WshShell();
     string shortcutAddr =  shortcutPath + @"\" + shortcutName;
     IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddr);
     shortcut.Description = description;
     shortcut.TargetPath = exePath;
     shortcut.Save();
 }
示例#8
0
 private void MakeShortcut(string shortcutFileName, string targetFileName)
 {
     IWshShell shell = new WshShell();
     IWshShortcut shortcut = shell.CreateShortcut(shortcutFileName) as IWshShortcut;
     shortcut.TargetPath = targetFileName;
     shortcut.Description = "Made with WinR!!! \n" + targetFileName;//Add path
     shortcut.WorkingDirectory = new FileInfo(targetFileName).Directory.FullName;
     shortcut.Save();
 }
示例#9
0
        //creates a shortcut for this application
        public static void addToStartup()
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("" + shortcutPath);

            shortcut.Description = "VPNTorrent Watcher";
            shortcut.TargetPath = Assembly.GetExecutingAssembly().Location;
            shortcut.Save();
        }
示例#10
0
文件: EnumLinks.cs 项目: oiotoxt/tint
        // 그냥 한번 해봤음
        public void CreateShortCut()
        {
            string path = @"C:\test.lnk";
            WshShell shell = new WshShell();
            IWshShortcut link = (IWshShortcut)shell.CreateShortcut(path);

            link.TargetPath = @"C:\stack.log";
            link.Save();
        }
示例#11
0
 static string GetShortcutTargetPath(string shortcut)
 {
     if (System.IO.File.Exists(shortcut))
     {
         WshShell shell = new WshShell();
         IWshShortcut link = (IWshShortcut)shell.CreateShortcut(shortcut);
         return link.TargetPath;
     }
     return string.Empty;
 }
示例#12
0
    /// <summary>
    ///     This method creates a shortcut
    /// </summary>
    /// <param name="shortcutName">The name of the shortcut</param>
    /// <param name="shortcutPath">The location of the shortcut</param>
    /// <param name="targetFileLocation">What should be linked</param>
    /// Require "using IWshRuntimeLibrary;", and a reference to Windows Script Host Model
    public static void createShortcut(string shortcutName, string shortcutPath, string targetFileLocation)
    {
        string shortcutLocation = System.IO.Path.Combine(shortcutPath, shortcutName + ".lnk");
        WshShell shell = new WshShell();
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

        shortcut.Description = "Keys";
        shortcut.TargetPath = targetFileLocation;
        shortcut.Save();
    }
        internal static bool ImportPcGame(WshShell shell, string linkPathName, IMLSection pcGamesSection )
        {

            IWshShortcut link = (IWshShortcut)shell.CreateShortcut(linkPathName);
            FileInfo linkFile = new FileInfo(link.FullName);

            string shortcutName = linkFile.Name;
            shortcutName = shortcutName.Remove(shortcutName.Length - 4, 4);

            FileVersionInfo myFileVersionInfo;

            try
            {
                myFileVersionInfo = FileVersionInfo.GetVersionInfo(link.TargetPath);
            }
            catch (Exception e)
            {
                Debugger.LogMessageToFile("An unexpected error ocurred while trying to retrieve this game's version information from the game's executable. The error was: "
                    + Environment.NewLine + e );

                return false;
            }

            string title = myFileVersionInfo.ProductName;
            string company = myFileVersionInfo.CompanyName;
            string language = myFileVersionInfo.Language;
            string description = myFileVersionInfo.FileDescription;
            string version = myFileVersionInfo.FileVersion;

            IMLItem item = pcGamesSection.FindItemByLocation(link.TargetPath);

            if (item == null)
                item = pcGamesSection.AddNewItem(title, link.TargetPath);
            else return false; 


            if (!String.IsNullOrEmpty(title))
            {
                item.Name = title;
                item.Tags["Title"] = title;
            }
            else
            {
                item.Name = shortcutName;
                item.Tags["Title"] = shortcutName;
            }
           
            item.Tags["Company"] = company;
            item.Tags["Language"] = language;
            item.Tags["Description"] = description;
            item.Tags["Version"] = version;
            item.SaveTags();
          
            return true;
        }
 public MainWindow()
 {
     InitializeComponent();
     settings_diag = new Settings();
     shell = new WshShell();
     try {
         listBox.ItemsSource = SteamDB.GetGames();
     } catch (Exception ex) {
         System.Console.WriteLine(ex);
     }
 }
示例#15
0
        public static void CreateShortcut(string shortcutName, string shortcutPath, string targetFileLocation, string shortcutDescription)
        {
            string shortcutLocation = System.IO.Path.Combine(shortcutPath, shortcutName + ".lnk");
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.Description = shortcutDescription;                                                             // The description of the shortcut
            shortcut.IconLocation = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase + ", 0";   // The icon of the shortcut
            shortcut.TargetPath = targetFileLocation + " -Startup";                                                // The path of the file that will launch when the shortcut is run
            shortcut.Save();                                                                                        // Save the shortcut
        }
 public bool CreateShortcut(WshShell shell, string path, string icon)
 {
     IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(path + @"\" + installDir + ".lnk");
     shortcut.Description = Name;
     shortcut.TargetPath = Properties.Settings.Default.steamDir + @"\steam.exe";
     shortcut.WorkingDirectory = Properties.Settings.Default.steamDir;
     shortcut.Arguments = "-applaunch " + Id;
     shortcut.IconLocation = FindExecutables()[0];
     shortcut.Save();
     return true;
 }
示例#17
0
 public static void CreateShortcut(String path, String targetPath, String args, String workingDirectory)
 {
     WshShell shell = new WshShell();
     IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(path);
     shortcut.TargetPath = targetPath;
     shortcut.Arguments = args;
     shortcut.WorkingDirectory = workingDirectory;
     shortcut.WindowStyle = 1;
     shortcut.Description = "Razzle For Laboratory VT Project";
     shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
     shortcut.Save();
 }
示例#18
0
        public static void AddToStartup(string title, string path, string args)
        {
            var shell = new WshShell();
            var shortcut = (IWshShortcut)shell.CreateShortcut($"{StartupFolder}\\{title}.lnk");

            shortcut.Description = title;
            shortcut.WindowStyle = 0;
            shortcut.WorkingDirectory = Path.GetDirectoryName(path);
            shortcut.TargetPath = path;
            shortcut.Arguments = args;
            shortcut.Save();
        }
示例#19
0
        public static void Create()
        {
            var WshShell = new WshShell();

            IWshRuntimeLibrary.IWshShortcut MyShortcut;

            MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@Environment.GetEnvironmentVariable("USERPROFILE") + "\\Desktop\\MadCow.lnk");
            MyShortcut.TargetPath = Application.ExecutablePath;
            MyShortcut.WorkingDirectory = Environment.CurrentDirectory;
            MyShortcut.Description = "MadCow";
            MyShortcut.Save();
        }
示例#20
0
        private void CreateShortcut(string name, int i)
        {
            string newfolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Notepad Executables");
            object shDesktop = (object)"Desktop";

            WshShell shell = new WshShell();
            if (!Directory.Exists(txtFolder.Text)) Directory.CreateDirectory(txtFolder.Text);
            string shortcutAddress = Path.Combine(txtFolder.Text,"Notepad" + i.ToString() + ".lnk");
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.TargetPath = Path.Combine(newfolder,name);
            shortcut.Save();
        }
示例#21
0
文件: SendTo.cs 项目: mard/Uploader
        public static void List()
        {
            string sendto = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);

            List<string> files = new List<string>();
            var a = Directory.GetFiles(sendto).Where(i => Path.GetExtension(i).Equals(".lnk")).ToList();

            IWshShell shell = new WshShell();
            IWshShortcut link = (IWshShortcut)shell.CreateShortcut(a[0]);

            Debug.WriteLine(link.TargetPath);
            Debug.WriteLine(link.WorkingDirectory);
        }
示例#22
0
 public static void Create(string name, int icon, string command, string parameters)
 {
     string link = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + Path.DirectorySeparatorChar + name + ".lnk";
     WshShell shell = new WshShell();
     IWshShortcut shortcut = shell.CreateShortcut(link) as IWshShortcut;
     if (null != shortcut)
     {
         shortcut.TargetPath = command;
         shortcut.Arguments = parameters;
         shortcut.IconLocation = string.Format(@"{0}\UbwToolsRes.dll,{1}", Application.StartupPath, icon);
         shortcut.Save();
     }
 }
示例#23
0
 private static void CreateShortcut()
 {
     try
     {
         string shortcutLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "LaunchSCCMUI.lnk");
         WshShell shell = new WshShell();
         IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
         shortcut.Description = "Launch SCCM UI";
         //shortcut.IconLocation = AppDomain.CurrentDomain.BaseDirectory + "\\ico.ico";
         shortcut.TargetPath = @"C:\tools\LaunchSCCMUI\LaunchSCCMUI.exe";
         shortcut.Save();
     }
     catch { }
 }
 public static void CreateAutorunShortcut()
 {
     var currentPath = Assembly.GetExecutingAssembly().Location;
     var shortcutLocation = GetAutorunPath();
     var description = "Simple keyboard layout switcher";
     if (System.IO.File.Exists(shortcutLocation))
     {
         return;
     }
     WshShell shell = new WshShell();
     IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
     shortcut.Description = description;
     shortcut.TargetPath = currentPath;
     shortcut.Save();
 }
示例#25
0
        public static void CreateShortcut(Prog prog)
        {
            var shell = new WshShell();
            string shortcutName = "<>:\"/\\|?*".ToCharArray().Union(Path.GetInvalidFileNameChars()).Aggregate(prog.Name, (current, c) => current.Replace(c.ToString(CultureInfo.InvariantCulture), ""));

            string shortcutAddress = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), shortcutName + ".lnk");

            var shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.Description = prog.Name + " via DTWrapper";
            shortcut.TargetPath = System.Reflection.Assembly.GetEntryAssembly().Location;
            shortcut.Arguments = "start " + prog.ID;
            shortcut.IconLocation = prog.Icon;
            shortcut.WorkingDirectory = Environment.CurrentDirectory;
            shortcut.Save();
        }
示例#26
0
        public static void Write(ShortCutParams p)
        {
            string args = p.arguments;
            if (!String.IsNullOrEmpty(args))
            {
                var rgx = new Regex("[\r\n]");
                args = rgx.Replace(args, " ");
            }

            var shell = new WshShell();
            IWshShortcut lnk = shell.CreateShortcut(p.lnkPath);
            lnk.TargetPath = p.targetPath;
            if (!String.IsNullOrEmpty(args)) lnk.Arguments = args;
            lnk.Save();
        }
 internal void CreateShortcut(string sendToPath, string fullPath)
 {
     string fileName = Path.GetFileNameWithoutExtension(fullPath);
     IWshShortcut shortcut;
     if (WindowsVer.Is64BitOs()) {
         WshShell wshShell = new WshShell();
         shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(sendToPath, fileName + ".lnk"));
     } else {
         WshShellClass wshShell = new WshShellClass();
         shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(sendToPath, fileName + ".lnk"));
     }
     shortcut.TargetPath = fullPath;
     shortcut.IconLocation = fullPath;
     shortcut.Save();
 }
示例#28
0
        /// <summary>
        ///     Retrieves target path from the given shortcut file. Shortcut file is a file with extension ".lnk"
        /// </summary>
        /// <param name="shortcutFile">Full path or relative path of the shortcut file.</param>
        /// <returns>The target path if the function succeeded.</returns>
        public static string GetShortcutTargetPath(string shortcutFile)
        {
            /* TODO Add implementations
             * See https://astoundingprogramming.wordpress.com/2012/12/17/how-to-get-the-target-of-a-windows-shortcut-c/
             * See http://stackoverflow.com/questions/13079569/how-do-i-get-the-path-name-from-a-file-shortcut-getting-exception
             */

            if (IsShortcutFile(shortcutFile))
            {
                var shell = new WshShell();
                var shortcut = (IWshShortcut)shell.CreateShortcut(shortcutFile);
                return shortcut.TargetPath;
            }
            throw new ArgumentException(shortcutFile);
        }
示例#29
0
        public static string ResolveShortcut(string filePath)
        {
            // IWshRuntimeLibrary is in the COM library "Windows Script Host Object Model"
            var shell = new WshShell();

            try
            {
                var shortcut = (IWshShortcut) shell.CreateShortcut(filePath);
                return shortcut.TargetPath;
            }
            catch (COMException)
            {
                // A COMException is thrown if the file is not a valid shortcut (.lnk) file 
                return null;
            }
        }
示例#30
0
        public static void Create()
        {
            var WshShell = new WshShell();

            IWshRuntimeLibrary.IWshShortcut MyShortcut;
            //For foreign users, The "Desktop" Folder Not always named "Desktop", e.g. "桌面" for chinese.
            //MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@Environment.GetEnvironmentVariable("USERPROFILE") + "\\Desktop\\MadCow.lnk");

            String desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            String lnk = desktop + "\\MadCow.lnk";
            MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(lnk);
            MyShortcut.TargetPath = Application.ExecutablePath;
            MyShortcut.WorkingDirectory = Program.programPath;
            MyShortcut.Description = "MadCow";
            MyShortcut.Save();
        }
示例#31
0
        //****************************************************************************************************************************************************************************************************

        /// <summary>
        /// Add the current app to the startup folder
        /// </summary>
        /// see: https://stackoverflow.com/questions/3391923/placing-a-shortcut-in-users-startup-folder-to-start-with-windows
        public static void AddAppToStartup()
        {
            if (IsAppInStartup)
            {
                return;
            }

            WshShell wshShell = new WshShell();

            IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(StartUpFolderPath + "\\" + AppName + ".lnk");

            shortcut.TargetPath       = System.Reflection.Assembly.GetExecutingAssembly().Location;
            shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(shortcut.TargetPath);
            shortcut.Description      = "Launch " + AppName;
            shortcut.Save();

            OnStaticPropertyChanged("IsAppInStartup");
        }
示例#32
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();
        }
示例#33
0
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        /// <param name="directory">快捷方式所处的文件夹</param>
        /// <param name="shortcutName">快捷方式名称</param>
        /// <param name="targetPath">目标路径</param>
        /// <param name="arguments">启动程序时的参数</param>
        /// <param name="description">描述</param>
        /// <param name="iconLocation">图标路径,格式为"可执行文件或DLL路径, 图标编号",
        /// 例如System.Environment.SystemDirectory + "\\" + "shell32.dll, 165"</param>
        /// <remarks></remarks>
        public static void CreateShortcut(string directory, string shortcutName, string targetPath, string arguments = "", string description = null, string iconLocation = null)
        {
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            string       shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName));
            WshShell     shell        = new WshShell();
            IWshShortcut shortcut     = (IWshShortcut)shell.CreateShortcut(shortcutPath);               //创建快捷方式对象

            shortcut.TargetPath       = targetPath;                                                     //指定目标路径
            shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);                              //设置起始位置
            shortcut.WindowStyle      = 1;                                                              //设置运行方式,默认为常规窗口
            shortcut.Arguments        = arguments;
            shortcut.Description      = description;                                                    //设置备注
            shortcut.IconLocation     = string.IsNullOrEmpty(iconLocation) ? targetPath : iconLocation; //设置图标路径
            shortcut.Save();                                                                            //保存快捷方式
        }
        // Delete Chromium desktop shortcut and replace with the updater's shortcut:
        private static void DesktopShortcut()
        {
            // Delete it
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            System.IO.File.Delete(Path.Combine(desktopPath, "Chromium.lnk"));

            // Make new shortcut:
            object       shDesktop       = (object)"Desktop";
            WshShell     shell           = new WshShell();
            string       shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Chromium.lnk";
            IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(shortcutAddress);

            shortcut.Description  = "Open Chromium";
            shortcut.TargetPath   = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Chromium\\ChromiumLauncher.exe";
            shortcut.IconLocation = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Chromium\\Application\\chrome.exe";
            shortcut.Save();
        }
示例#35
0
        private void CreateSupportShortcut(string serverUrl, string deviceUuid, bool createSupportShortcut)
        {
            var shell            = new WshShell();
            var shortcutLocation = Path.Combine(InstallPath, "Get Support.lnk");
            var shortcut         = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.Description  = "Get IT support";
            shortcut.IconLocation = Path.Combine(InstallPath, "Remotely_Agent.exe");
            shortcut.TargetPath   = serverUrl.TrimEnd('/') + $"/GetSupport?deviceID={deviceUuid}";
            shortcut.Save();

            if (createSupportShortcut)
            {
                var systemRoot    = Path.GetPathRoot(Environment.SystemDirectory);
                var publicDesktop = Path.Combine(systemRoot, "Users", "Public", "Desktop", "Get Support.lnk");
                FileIO.Copy(shortcutLocation, publicDesktop, true);
            }
        }
示例#36
0
        private void CreateBatFileShortcut(string path, string scp, string fname)
        {
            ////string cuser = "******";
            //string textfile = cuser + ".bat";
            //string path = Path.Combine(Environment.CurrentDirectory, textfile);
            //string scfile = "METAbolt- " + cuser + " BAT.lnk";
            string sc = scp;   // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), scfile);

            // now create desktop shortcut
            WshShell     shell = new WshShell();
            IWshShortcut link  = (IWshShortcut)shell.CreateShortcut(sc);

            link.TargetPath       = path;
            link.WorkingDirectory = METAbolt.DataFolder.GetDataFolder();    //Application.StartupPath.ToString();
            link.Description      = "METAbolt_" + fname + " BAT shortcut";
            //link.IconLocation = Environment.CurrentDirectory + "";
            link.Save();
        }
示例#37
0
        public void CreateStartupFolderShortcut()
        {
            WshShell wshShell = new WshShell();

            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 My Application";
            shortcut.Save();
        }
示例#38
0
        private void CreateShortcut(string folder, string name, string target, string description)
        {
            string shortcutFullName = Path.Combine(folder, name + ".lnk");

            try
            {
                WshShell     shell = new WshShell();
                IWshShortcut link  = (IWshShortcut)shell.CreateShortcut(shortcutFullName);
                link.TargetPath  = target;
                link.Description = description;
                link.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("The shortcut \"{0}\" could not be created.\n\n{1}", shortcutFullName, ex.ToString()),
                                "Create Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private static IWshShortcut GetShortcut(IFile file)
        {
            try
            {
                var extension = file.Path.GetExtension().Name;
                if (extension != "lnk" && extension != "url")
                {
                    return(null);
                }

                var shell = new WshShell();
                return(shell.CreateShortcut(file.Path.FullPath) as IWshShortcut);
            }
            catch (COMException)
            {
                return(null);
            }
        }
示例#40
0
        public static void AddMenuItem()
        {
            string sendto       = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
            string shortcutpath = sendto + Path.DirectorySeparatorChar + "PDFUtilities.lnk";

            WshShell shell = new WshShell();

            if (System.IO.File.Exists(shortcutpath))
            {
                System.IO.File.Delete(shortcutpath);
            }

            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutpath);

            shortcut.Description = "Shortcut for PDF Utilities";
            shortcut.TargetPath  = System.Reflection.Assembly.GetExecutingAssembly().Location;
            shortcut.Save();
        }
示例#41
0
        public static bool enableStartup()
        {
            // https://bytescout.com/blog/create-shortcuts-in-c-and-vbnet.html
            step++;
            var args = step.ToString();

            var startupFolderPath          = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup);
            var shell                      = new WshShell();
            var shortCutLinkFilePath       = Path.Combine(startupFolderPath, @"JimmyDeploy.lnk");
            var windowsApplicationShortcut = (IWshShortcut)shell.CreateShortcut(shortCutLinkFilePath);

            windowsApplicationShortcut.Description      = "How to create short for application example";
            windowsApplicationShortcut.WorkingDirectory = System.Windows.Forms.Application.StartupPath;
            windowsApplicationShortcut.TargetPath       = System.Windows.Forms.Application.ExecutablePath;
            windowsApplicationShortcut.Arguments        = args;
            windowsApplicationShortcut.Save();
            return(true);
        }
示例#42
0
        private static void AutoLaunch()
        {
            var direcroty = Path.Combine(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\", "FileCopy.lnk");

            if (System.IO.File.Exists(direcroty))
            {
                return;
            }
            RequireAdministrator();
            var shell    = new WshShell();
            var shortcut = shell.CreateShortcut(direcroty) as IWshShortcut;

            shortcut.TargetPath   = Application.ExecutablePath;
            shortcut.Arguments    = "-auto";
            shortcut.WindowStyle  = 2;
            shortcut.IconLocation = Application.ExecutablePath;
            shortcut.Save();
        }
示例#43
0
        public static void CreateDesktopShortcut()
        {
            string DesktopShortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Easy Survey.lnk";
            string TargetAppPath       = Assembly.GetExecutingAssembly().Location;
            string WorkingDirectoryApp = Path.GetDirectoryName(TargetAppPath);

            WshShell     wsh      = new WshShell();
            IWshShortcut shortcut = wsh.CreateShortcut(DesktopShortcutPath) as IWshShortcut;

            shortcut.Arguments  = "";
            shortcut.TargetPath = TargetAppPath;
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Easy Survey Software";
            shortcut.WorkingDirectory = WorkingDirectoryApp;
            shortcut.IconLocation     = TargetAppPath;
            shortcut.Save();
        }
示例#44
0
        private void RegisterApp(string appPath)
        {
            string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
            string appStartMenuPath    = Path.Combine(commonStartMenuPath, "Programs", "TwometerVR");

            if (!Directory.Exists(appStartMenuPath))
            {
                Directory.CreateDirectory(appStartMenuPath);
            }

            string       shortcutLocation = Path.Combine(appStartMenuPath, "TwometerVR" + ".lnk");
            WshShell     shell            = new WshShell();
            IWshShortcut shortcut         = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.Description = "TwometerVR Service";
            shortcut.TargetPath  = appPath;
            shortcut.Save();
        }
示例#45
0
 private void CreateShortCut(Environment.SpecialFolder flder, string DosyaYolu)
 {
     try
     {
         IWshRuntimeLibrary.IWshShortcut kisayol;
         WshShell ws = new WshShell();
         kisayol              = (IWshShortcut)ws.CreateShortcut(Environment.GetFolderPath(flder) + DosyaYolu);
         kisayol.TargetPath   = Application.ExecutablePath;
         kisayol.Description  = "This software has been made for decreasing shortcuts on the desktop. Use for good days.\nMade By : Nusty\nPath : " + Application.ExecutablePath;
         kisayol.IconLocation = Application.StartupPath + @"\monitor.ico";
         kisayol.Save();
     }
     catch (Exception ex)
     {
         MessageUtil.Error("Shortcut could not be created.");
         Logger.WriteException(ex, "Shortcut could not be created.", "ERR_SHORT_CREATE");;
     }
 }
示例#46
0
        CreateStartMenuShortcut
        (
            AddInPostDeploymentActionArgs args
        )
        {
            // This was adapted from Rustam Irzaev's reply to this post:
            //
            //   http://stackoverflow.com/questions/4897655/create-shortcut-on-desktop-c-sharp

            WshShell wshShell = new WshShell();

            IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(
                GetStartMenuShortcutFilePath());

            shortcut.Description = StartMenuShortcutDescription;
            shortcut.TargetPath  = GetNodeXLTemplatePath(args);
            shortcut.Save();
        }
示例#47
0
        private static void CreateShortcuts()
        {
            // From http://stackoverflow.com/questions/25024785/how-to-create-start-menu-shortcut
            string startMenuPath       = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
            string startMenuFolderPath = Path.Combine(startMenuPath, "Wyam.Windows");

            if (!Directory.Exists(startMenuFolderPath))
            {
                Directory.CreateDirectory(startMenuFolderPath);
            }
            string       shortcutLocation = Path.Combine(startMenuFolderPath, "Wyam Command Prompt.lnk");
            WshShell     shell            = new WshShell();
            IWshShortcut shortcut         = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.TargetPath = "cmd.exe";
            shortcut.Arguments  = $"/k {Path.Combine(GetInstallDirectory(), "wyam.prompt.cmd")}";
            shortcut.Save();
        }
示例#48
0
        /// <summary>
        /// AUCを実行
        /// </summary>
        object Auc(string command, string arg)
        {
            Type WshShell;

            WshShell = Type.GetTypeFromProgID("Wscript.Shell");
            Object obj = Activator.CreateInstance(WshShell);

            Object type = 2;
            Object wait = true;

            return(WshShell.InvokeMember(
                       "Run",
                       BindingFlags.InvokeMethod,
                       null,
                       obj,
                       new Object[] { Path.Combine(Settings.Default.AUCDir, "auc_" + command + ".exe ") + arg, type, wait }
                       ));
        }
示例#49
0
        public Task CreateShortCut()
        {
            string      AppDataLocal     = Path.GetFullPath(@"C:\");
            string      ShortcutTarget   = Path.GetFullPath(AppDataLocal + @"\IDR\DocumentRepository.exe");
            string      ShortcutLink     = Path.GetFullPath(AppDataLocal + @"\IDR\DocumentRepository.lnk");
            string      ShortcutLocation = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Document Repository.lnk");
            string      AppDirectory     = Path.GetFullPath(AppDataLocal + @"\IDR");
            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);
        }
示例#50
0
        // Read current coin from shortcut in user's startup folder
        public static Shortcut GetCurrentCoin()
        {
            WshShell shell = new WshShell();

            string[] files   = null;
            string   startup = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            files = Directory.GetFiles(startup, "start-miner-*.lnk");
            if (files.Length > 0)
            {
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(files[0]);
                return(new Shortcut(shortcut.TargetPath, shortcut.Arguments, shortcut.WorkingDirectory, shortcut.Description));
            }
            else
            {
                return(null);
            }
        }
示例#51
0
 private static void CreateShortCut(string sourceFileName, string targetPath)
 {
     try
     {
         WshShell     wsh      = new WshShell();
         IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + sourceFileName.Replace("_WPF", "") + ".lnk") as IWshShortcut;
         shortcut.Arguments        = "";
         shortcut.TargetPath       = targetPath + @"\" + sourceFileName + ".exe";
         shortcut.WindowStyle      = 1;
         shortcut.WorkingDirectory = targetPath;
         shortcut.IconLocation     = targetPath + @"\image.ico";
         shortcut.Save();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#52
0
        private void CreateShortcut(string linkname)
        {
            if (!Directory.Exists(installPath + "Resources\\shortcuts"))
            {
                Directory.CreateDirectory(installPath + "Resources\\shortcuts");
            }
            WshShell     wsh      = new WshShell();
            IWshShortcut shortcut = wsh.CreateShortcut(
                installPath + "Resources\\shortcuts" + "\\" + EditTitle.Text + ".lnk") as IWshShortcut;

            shortcut.Arguments        = "";
            shortcut.TargetPath       = linkname;
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Shortcut to " + EditTitle.Text;
            shortcut.WorkingDirectory = "C:\\App";
            shortcut.IconLocation     = linkname;
            shortcut.Save();
        }
示例#53
0
        private void startupWindows_CheckedChanged(object sender, EventArgs e)
        {
            string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ToolSL.lnk";

            if (Alphaleonis.Win32.Filesystem.File.Exists(shortcutAddress))
            {
                Alphaleonis.Win32.Filesystem.File.Delete(shortcutAddress);
            }
            else
            {
                object       shDesktop = "ToolSL";
                WshShell     shell     = new WshShell();
                IWshShortcut shortcut  = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description = "Shortcut for SpinLegends tool";
                shortcut.TargetPath  = System.Reflection.Assembly.GetExecutingAssembly().Location;
                shortcut.Save();
            }
        }
示例#54
0
        public static IEnumerable <InternetShortcut> Decode(IDataObject data)
        {
            WshShell shell = new WshShell();

            foreach (FileGroupDescriptor.File i in FileGroupDescriptor.Decode(data))
            {
                if (i.Name.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
                {
                    string          path  = i.Write(System.Environment.GetEnvironmentVariable("TEMP"));
                    IWshURLShortcut wshSc = (IWshURLShortcut)shell.CreateShortcut(path);
                    System.IO.File.Delete(path);
                    InternetShortcut sc = new InternetShortcut();
                    sc.Name = i.Name;
                    sc.Url  = wshSc.TargetPath;
                    yield return(sc);
                }
            }
        }
 private void CreateShortCut(Environment.SpecialFolder flder, string filePath)
 {
     try
     {
         IWshRuntimeLibrary.IWshShortcut shortCut;
         WshShell ws = new WshShell();
         shortCut              = (IWshShortcut)ws.CreateShortcut(Environment.GetFolderPath(flder) + filePath);
         shortCut.TargetPath   = Application.ExecutablePath;
         shortCut.Description  = "This software has been made for managing all bookmarks in one program. Use for good days.\nMade By : Musty\nPath : " + Application.ExecutablePath;
         shortCut.IconLocation = Application.StartupPath + @"\monitor.ico";
         shortCut.Save();
     }
     catch (Exception ex)
     {
         MessageUtil.Error("Shortcut could not be created.");
         FreeLogger.LogMethod(ex, this.Name, "CreateShortCut");
     }
 }
示例#56
0
        void ExtractAsync(string to, ZipFile zip)
        {
            zip.ExtractAll(to, ExtractExistingFileAction.OverwriteSilently);
            zip.Dispose();

            MessageBox.Show("Установка завершена");

            Properties.Settings.Default.Save();
            WshShell     shell        = new WshShell();
            string       shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Launcher Siberia RoM.lnk";
            IWshShortcut shortcut     = (IWshShortcut)shell.CreateShortcut(shortcutPath);

            shortcut.Description      = "Siberia Launcher";
            shortcut.WorkingDirectory = path_to;
            shortcut.TargetPath       = path_to + "//LauncherSiberia.exe";
            shortcut.Save();
            Application.Exit();
        }
示例#57
0
        private static bool CreateShortcut(string shortcutPath, string targetPath, string arguments = "")
        {
            if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                DeleteShortcut(shortcutPath);

                WshShell     shell    = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
                shortcut.TargetPath       = targetPath;
                shortcut.Arguments        = arguments;
                shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
                shortcut.Save();

                return(true);
            }

            return(false);
        }
示例#58
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);
     }
 }
示例#59
0
        private void CreateDevPromptShortcuts(string frcHomePath)
        {
#if !MAC && !LINUX
            CreateFRCShortcutsFolder();
            object       shDesktop       = "StartMenu";
            WshShell     shell           = new WshShell();
            string       shortcutAddress = shell.SpecialFolders.Item(ref shDesktop) + $"\\FRC {upgradeConfig.FrcYear}\\FRC Developer Command Prompt {upgradeConfig.FrcYear}.lnk";
            IWshShortcut shortcut        = shell.CreateShortcut(shortcutAddress);
            shortcut.Description = "Shortcut for FRC Development Command Prompt";
            shortcut.TargetPath  = @"%comspec%";

            shortcut.Arguments = $"/k \"{Path.Combine(frcHomePath, "frccode", "frcvars.bat")}\"";
            object shDocuments = "MyDocuments";
            shortcut.WorkingDirectory = shell.SpecialFolders.Item(ref shDocuments);
            shortcut.IconLocation     = Path.Combine(frcHomePath, upgradeConfig.PathFolder, "wpilib-256.ico") + ",0";
            shortcut.Save();
#endif
        }
示例#60
0
        public bool AddToStartupDirectory(string ShortcutName = null, string TargetExecutablePath = null, string Description = null, string ShortcutIconPath = null, bool HideShortcutFile = false)
        {
            try
            {
                if (String.IsNullOrEmpty(TargetExecutablePath))
                {
                    TargetExecutablePath = Application.ExecutablePath;
                }

                WshShell wsh = new WshShell();
                string   startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                var      appShortcut       = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(startupFolderPath + "\\" + ShortcutName + ".lnk");

                appShortcut.WorkingDirectory = Application.StartupPath;
                appShortcut.TargetPath       = Application.ExecutablePath;

                if (!String.IsNullOrEmpty(Description))
                {
                    appShortcut.Description = Description;
                }
                if (!String.IsNullOrEmpty(ShortcutIconPath))
                {
                    appShortcut.IconLocation = ShortcutIconPath;
                }
                if (String.IsNullOrEmpty(ShortcutName))
                {
                    ShortcutName = Path.GetFileNameWithoutExtension(Application.ExecutablePath.ToString());
                }

                appShortcut.Save();

                if (HideShortcutFile)
                {
                    SetFileAttributesHidden(startupFolderPath + "\\" + ShortcutName + ".lnk");
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
        }