Esempio n. 1
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;
        }
Esempio n. 2
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 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
            };
        }
Esempio n. 4
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;
 }
 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;
 }
Esempio n. 6
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();
 }
Esempio n. 7
0
        // 그냥 한번 해봤음
        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();
        }
Esempio n. 8
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();
 }
Esempio n. 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();
        }
Esempio n. 10
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;
 }
Esempio n. 11
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 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;
 }
Esempio n. 14
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
        }
Esempio n. 15
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();
        }
Esempio n. 16
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();
        }
Esempio n. 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();
 }
Esempio n. 18
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();
        }
Esempio n. 19
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();
     }
 }
Esempio n. 20
0
        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);
        }
Esempio n. 21
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 { }
 }
 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();
 }
Esempio n. 23
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();
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
 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();
 }
Esempio n. 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();
        }
Esempio n. 27
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();
        }
Esempio n. 28
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;
            }
        }
Esempio n. 29
0
        public static FileInfo FindFirstUserProfileShortcutInDir(string userProfileName, DirectoryInfo shortcutDir)
        {
            FileInfo foundShortcut = null;

            var shell = new WshShell();

            // for all shortcuts in shortcutDir
            foreach (var fi in shortcutDir.GetFiles("*." + SystemDetails.WinShortcutFileExt, SearchOption.TopDirectoryOnly))
            {
                // get shortcut
                var link = (IWshShortcut)shell.CreateShortcut(fi.FullName);

                // chrome shortcut?
                var targetMatches = link.TargetPath.Equals(SystemDetails.ChromeExeFile.FullName);

                // chrome default?
                var targetDefault = false;
                if (SystemDetails.IsDefaultProfile(userProfileName) &&
                    link.Arguments.Equals(""))
                {
                    targetDefault = true;
                }

                // chrome user data dir arg present?
                var argUserDataDirPresent = link.Arguments.StartsWith(SystemDetails.ChromeExeArgId + SystemDetails.ChromeUserDataDirArg);

                // chrome user data dir arg that specifies this user profile?
                var argUserDataDirUserProfileNameMatches = false;
                if (argUserDataDirPresent)
                {
                    argUserDataDirUserProfileNameMatches = IsUserDataDirArgWithUserProfile(link, userProfileName);
                }

                // if all the stars align, we have found our shortcut!
                if ((targetMatches && targetDefault) ||
                    (targetMatches && argUserDataDirPresent && argUserDataDirUserProfileNameMatches))
                {
                    // found it, and ...
                    foundShortcut = fi;
                    // ... we don't need to look at the other shortcuts!
                    break;
                }
            }

            return foundShortcut;
        }
Esempio n. 30
0
        public static void CreateShortcut(ShortcutUnit Shortcut)
        {
            String IconPath = Path.GetFullPath( Shortcut.IconLocation );
            String Target = Path.GetFullPath( Shortcut.TargetPath );

            WshShell shell = new WshShell();
            IWshShortcut shortcut  = (IWshShortcut)shell.CreateShortcut( Shortcut.LinkName );
            shortcut.TargetPath = Shortcut.TargetPath;
            shortcut.WindowStyle = 1;
            shortcut.IconLocation = Shortcut.IconLocation;
            shortcut.Description = Shortcut.Description;
            //Set up this propertise, the "current location" would be the application folder,
            //rather than the location of shortcut.
            shortcut.WorkingDirectory = Path.GetDirectoryName( Target );

            shortcut.Save();
        }
Esempio n. 31
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);
        }
Esempio n. 32
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();
        }
Esempio n. 33
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();
        }
Esempio n. 34
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{upgradeConfig.FrcYear}.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
        }
Esempio n. 35
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;
     }
 }
Esempio n. 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();
        }
Esempio n. 37
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();
        }
Esempio n. 38
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();
        }
Esempio n. 39
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();
        }
Esempio n. 40
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");
        }
Esempio n. 41
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);
            }
        }
Esempio n. 42
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();
        }
 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");
     }
 }
Esempio n. 44
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();                                                                            //保存快捷方式
        }
Esempio n. 45
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);
     }
 }
Esempio n. 46
0
        public static void AddShortcuts()
        {
            try
            {
                string pathToExe           = Path.Combine(Program.InstallPath, "XRmonitorsUI.exe");
                string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
                string appStartMenuPath    = Path.Combine(commonStartMenuPath, "Programs", "XRmonitors");

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

                string shortcutLocation = Path.Combine(appStartMenuPath, "XRmonitors" + ".lnk");

                WshShell     shell    = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

                shortcut.Description  = "XRmonitors Virtual Multi-Monitors for the Workplace";
                shortcut.IconLocation = pathToExe + ",0";
                shortcut.TargetPath   = pathToExe;
                shortcut.Save();

                shortcut = null;
                shell    = null;


                string commonDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);

                string desktopShortcutLocation = Path.Combine(commonDesktopPath, "XRmonitors" + ".lnk");

                shell    = new WshShell();
                shortcut = (IWshShortcut)shell.CreateShortcut(desktopShortcutLocation);

                shortcut.Description  = "XRmonitors Virtual Multi-Monitors for the Workplace";
                shortcut.IconLocation = pathToExe + ",0";
                shortcut.TargetPath   = pathToExe;
                shortcut.Save();
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while adding shortcuts to the start menu: " + e.ToString(), "XRmonitors - Adding Shortcuts Failed");
            }
        }
Esempio n. 47
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);
            }
        }
Esempio n. 48
0
        public static void UnchangeShortcutForUpdate()
        {
            try
            {
                string   pathDesktop       = Environment.GetFolderPath(Environment.SpecialFolder.Desktop /*CommonDesktopDirectory*/); // Каталог рабочего стола юзера
                string   pathCommonDesktop = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);             // Каталог рабочего стола общий
                string[] found1            = Directory.GetFiles(pathDesktop, "*.lnk", SearchOption.TopDirectoryOnly);                 // Получаем пути ко всем ярлыкам на раб.столе
                string[] found2            = Directory.GetFiles(pathCommonDesktop, "*.lnk", SearchOption.TopDirectoryOnly);
                string[] foundlnk          = found1.Union(found2).ToArray();                                                          // объдиняем найденые ярлыки на десктопах
                string   pathApp           = Data.DestinDir + @"\NVCIUpdater.exe";
                int      countShortcut     = 0;

                foreach (string lnk in foundlnk)
                {
                    IWshShell    wsh  = new WshShell();
                    IWshShortcut link = (IWshShortcut)wsh.CreateShortcut(lnk);                                // получаем свойства ярлыка

                    if (link.WorkingDirectory.StartsWith(Data.DestinDir, StringComparison.OrdinalIgnoreCase)) // проверяем, совпадает ли WorkingDirectory с рабочей папкой "ушек"
                    {
                        if (String.Compare(link.TargetPath, pathApp, true) == 0)                              // если TargetPath ссылается на NVCIUpdater, то изменяем свойства ярлыка
                        {
                            string[] arg = link.Arguments.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            link.TargetPath       = arg[0];
                            link.Arguments        = String.Join(" ", arg, 1, arg.Length - 1);
                            link.WorkingDirectory = Data.DestinDir;
                            link.Save();  // сохраняем сделаные изменения
                            countShortcut++;
                        }
                    }
                }
                if (countShortcut != 0)
                {
                    MessageBox.Show(("Ярлыки, в количестве " + countShortcut + " шт. изменены в стандартное состояние."), "NVCIUpdater", 0, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("На рабочем столе, не найдено ярлыков, которые нужно вернуть в стандартное состояние.", "NVCIUpdater", 0, MessageBoxIcon.Information);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "NVCIUpdater", 0, MessageBoxIcon.Error);
            }
        }
        private static void CheckIfLegitimate()
        {
            try
            {
                bool            legit           = true;
                List <FileInfo> parserShortcuts = GetParserShortcuts();

                if (parserShortcuts.Count > 0)
                {
                    foreach (FileInfo file in parserShortcuts)
                    {
                        if (legit)
                        {
                            WshShell     wshShell = new WshShell();
                            IWshShortcut shortcut = wshShell.CreateShortcut(file.FullName) as IWshShortcut;

                            if (shortcut.TargetPath != Application.ExecutablePath)
                            {
                                shortcut.TargetPath = Application.ExecutablePath;
                            }
                            if (!shortcut.Arguments.ToLower().Contains($"{Data.parameterPrefix}minimized"))
                            {
                                shortcut.Arguments = $"{Data.parameterPrefix}minimized";
                            }
                            if (shortcut.WorkingDirectory != Application.StartupPath)
                            {
                                shortcut.WorkingDirectory = Application.StartupPath;
                            }

                            shortcut.Save();
                            legit = false;
                        }
                        else
                        {
                            file.Delete();
                        }
                    }
                }
            }
            catch
            {
                // Silent Exception
            }
        }
Esempio n. 50
0
        private void CreateShortcutBtn_MouseClick(object sender, MouseEventArgs e)
        {
            try {
                string filename = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Запускатр Боевых Братьев.lnk";
                if (!IOFile.Exists(filename))
                {
                    WshShell     wsh      = new WshShell();
                    IWshShortcut shortcut = wsh.CreateShortcut(filename) as IWshShortcut;
                    shortcut.Arguments        = "";
                    shortcut.TargetPath       = Application.ExecutablePath;
                    shortcut.WorkingDirectory = Program.LoncherPath;
                    shortcut.WindowStyle      = 1;
                    string iconFile      = Program.LoncherDataPath + "shortcutIcon.ico";
                    bool   validIconFile = IOFile.Exists(iconFile);
                    if (!validIconFile)
                    {
                        string exename = Program.GamePath + Program.LoncherSettings.ExeName;

                        if (IOFile.Exists(PreloaderForm.ICON_FILE))
                        {
                            PngIconConverter.Convert(PreloaderForm.ICON_FILE, iconFile);
                            validIconFile = true;
                        }
                        else if (IOFile.Exists(exename) && exename.EndsWith(".exe"))
                        {
                            Icon exeIcon = Icon.ExtractAssociatedIcon(exename);
                            if (exeIcon != null)
                            {
                                Bitmap exeBmp = exeIcon.ToBitmap();
                                PngIconConverter.Convert(exeBmp, iconFile);
                                validIconFile = true;
                            }
                        }
                    }
                    if (validIconFile)
                    {
                        shortcut.IconLocation = iconFile;
                    }
                    shortcut.Save();
                }
            } catch (Exception ex) {
                YobaDialog.ShowDialog(ex.Message);
            }
        }
Esempio n. 51
0
        public static void CreateShortcut(string shortcutName, string shortcutPath, string saveFile)
        {
            string shortcutLocation = Path.Combine(shortcutPath, shortcutName + ".lnk");

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

            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.Description = "Quickstart shortcut for a \"The Game\" save file";
            //shortcut.IconLocation = "";
            shortcut.TargetPath       = Directory.GetCurrentDirectory() + "\\The Game.exe";
            shortcut.Arguments        = saveFile;
            shortcut.WorkingDirectory = Directory.GetCurrentDirectory();
            shortcut.Save();
        }
Esempio n. 52
0
        public static string GetExePathFromInk(string path)
        {
            var shell    = new WshShell();
            var shortcut = (WshShortcut)shell.CreateShortcut(path);

            if (File.Exists(shortcut.TargetPath))
            {
                return(shortcut.TargetPath);
            }
            if (shortcut.TargetPath.Contains("Program Files (x86)") && File.Exists(shortcut.TargetPath.Replace("Program Files (x86)", "Program Files")))
            {
                return(shortcut.TargetPath.Replace("Program Files (x86)", "Program Files"));
            }
            if (shortcut.TargetPath.Contains("Program Files") && !shortcut.TargetPath.Contains("Program Files (x86)") && File.Exists(shortcut.TargetPath.Replace("Program Files", "Program Files (x86)")))
            {
                return(shortcut.TargetPath.Replace("Program Files", "Program Files (x86)"));
            }
            return(null);
        }
Esempio n. 53
0
        static void Main(string[] args)
        {
            Console.WriteLine("Do you want to create a Send To shortcut?(y/n)");
            var response = Console.ReadKey();

            if (response.KeyChar.ToString().ToLower() == "y")
            {
                // add shortcut to app in the following folder:
                // C:\Users\<username>\AppData\Roaming\Microsoft\Windows\SendTo

                //path should be 'C:\Users\<username>\AppData\Roaming'
                string appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string sendtoPath  = Path.Combine(appdatapath, @"Microsoft\Windows\SendTo");
                string path        = Path.Combine(sendtoPath, @"Add to Runnable Sample.lnk");
                //object shDesktop = (object)"Test shortcut - " + DateTime.Now.ToString("HH-mm-ss");
                try
                {
                    WshShell     shell           = new WshShell();
                    string       shortcutAddress = Directory.GetCurrentDirectory();// @"D:\MyWorkProjects\ZipToRunnableProjectWPF\ZipToRunnableProjectWPF\bin\Debug";
                    IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(path);
                    shortcut.Description = "New shortcut for Recycle Bin";
                    //shortcut.Hotkey = "Ctrl+Shift+N";
                    //shortcut.IconLocation = @"C:\WINDOWS\System32\imageres.dll";
                    shortcut.WorkingDirectory = shortcutAddress;
                    shortcut.TargetPath       = Path.Combine(shortcutAddress, "ZipToRunnableProjectWPF.exe");
                    shortcut.Save();
                }
                catch (Exception)
                {
                    Console.WriteLine("Exception occurred");
                    throw;
                }
                Console.WriteLine("Shortcut created successfully");
            }
            ////accessing the CurrentUser root element
            ////and adding "OurSettings" subkey to the "SOFTWARE" subkey
            //RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\OurSettings");

            ////storing the values
            //key.SetValue("Setting1", "This is our setting 1");
            //key.SetValue("Setting2", "This is our setting 2");
            //key.Close();
        }
Esempio n. 54
0
        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();
        }
Esempio n. 55
0
        private void SetRunAtStartup(bool doit)
        {
            var myPath          = System.Reflection.Assembly.GetEntryAssembly().Location;
            var startupDir      = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            var shortcutAddress = Path.Combine(startupDir, "Wallpapernator.lnk");

            if (!doit && System.IO.File.Exists(shortcutAddress))
            {
                System.IO.File.Delete(shortcutAddress);
                return;
            }

            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);

            shortcut.Description = "Wallpapernator";
            shortcut.TargetPath  = myPath;
            shortcut.Save();
        }
Esempio n. 56
0
        private async void DownloadFiles()
        {
            try
            {
                DownloadButton.IsEnabled = false;
                DownloadButton.Content   = "Устанавливаю";

                string   Url   = "http://wolf.wolfproject.ru/Installer/";
                string[] Files = { "Wolf.exe", "UIEngine.dll", "WolfService.exe" };

                string Path          = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\" + "Wolf Project" + @"\" + Files[0];
                string PathDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + @"\" + "Wolf Project";

                using WebClient WebClient = new WebClient();

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

                foreach (string File in Files)
                {
                    LabelProgress.Content = $"Идет загрузка: {File}";

                    await WebClient.DownloadFileTaskAsync(Url + File, PathDirectory + @"\" + File);
                }

                WshShell     WshShell     = new WshShell();
                IWshShortcut IWshShortcut = (IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + "Wolf.lnk");

                IWshShortcut.TargetPath       = Path;
                IWshShortcut.WorkingDirectory = PathDirectory;
                IWshShortcut.IconLocation     = Path;
                IWshShortcut.Save();

InstallService:
                try
                {
                    ManagedInstallerClass.InstallHelper(new[] { @$ "{PathDirectory}\WolfService.exe" });
                }
                catch
                {
                    ManagedInstallerClass.InstallHelper(new[] { "/u", @$ "{PathDirectory}\WolfService.exe" });
Esempio n. 57
0
 /// <summary>
 /// 检查提供的路径,判断是否lnk文件
 /// </summary>
 /// <param name="path"></param>
 private static void CheckPath(string path)
 {
     if (path.ToLower().IndexOf(".lnk") >= 0)
     {
         WshShell     shell = new WshShell();
         IWshShortcut iss   = (IWshShortcut)shell.CreateShortcut(path);
         lnkInfo.Name             = FileOperation.GetNameWithoutExtension(FileOperation.GetName(path));
         lnkInfo.TargetPath       = iss.TargetPath;
         lnkInfo.WorkingDirectory = iss.WorkingDirectory;
         lnkInfo.Arguments        = iss.Arguments;
     }
     else
     {
         lnkInfo.Name             = "";
         lnkInfo.TargetPath       = path;
         lnkInfo.WorkingDirectory = "";
         lnkInfo.Arguments        = "";
     }
 }
Esempio n. 58
0
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        /// <param name="directory">快捷方式所处的文件夹</param>
        /// <param name="shortcutName">快捷方式名称</param>
        /// <param name="targetPath">目标路径</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 description = null, string iconLocation = null)
        {
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var shortcutPath = Path.Combine(directory, $"{shortcutName}.lnk");
            var shell        = new WshShell();
            var shortcut     = (IWshShortcut)shell.CreateShortcut(shortcutPath);                             //创建快捷方式对象

            shortcut.TargetPath       = targetPath;                                                          //指定目标路径
            shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);                                   //设置起始位置
            shortcut.WindowStyle      = 1;                                                                   //设置运行方式,默认为常规窗口
            shortcut.Description      = description;                                                         //设置备注
            shortcut.IconLocation     = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; //设置图标路径
            shortcut.Save();                                                                                 //保存快捷方式
        }
Esempio n. 59
0
        private void CreateShortcut(string gamepath, string xeniapath)
        {
            if (button10.ForeColor == Color.Red)
            {
                MessageBox.Show("Select Xenia path");
            }
            else
            {
                string currentpath = Directory.GetCurrentDirectory();
                if (System.IO.File.Exists(currentpath + @"\game.lnk"))
                {
                    System.IO.File.Delete(currentpath + @"\game.lnk");
                }


                WshShell shell = new WshShell();

                string       shortcutAddress = currentpath + @"\" + "game" + @".lnk";
                IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.TargetPath = xeniapath;

                if (fullscreen)
                {
                    shortcut.Arguments = @"--fullscreen" + @" --target=" + gamepath;
                }

                if (!fullscreen)
                {
                    shortcut.Arguments = @"--target=" + gamepath;
                }

                shortcut.Save();

                try
                {
                    Process.Start(currentpath + @"\game.lnk");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
        /// <summary>
        /// Add a shortcut to the startmenu.
        /// </summary>
        /// <param name="pathToExe">The absolute path to the executable.</param>
        /// <param name="pathToIco">The absolute path to the icon.</param>
        /// <param name="appName">The name of the application.</param>
        /// <param name="description">The description of the application. Defaults to appName.</param>
        public static void AddShortcutToStartmenu(string pathToExe, string pathToIco)
        {
            string startMenuPath    = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
            string appStartMenuPath = Path.Combine(startMenuPath, "Programs", AppInfo.Name);

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

            string       shortcutLocation = Path.Combine(appStartMenuPath, string.Format("{0}" + ".lnk", AppInfo.Name));
            WshShell     shell            = new WshShell();
            IWshShortcut shortcut         = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.Description  = AppInfo.Name;
            shortcut.IconLocation = @pathToIco;
            shortcut.TargetPath   = @pathToExe;
            shortcut.Save();
        }