示例#1
0
        /// <summary>
        /// ساخت میانبر
        /// </summary>
        /// <param name="fileName">فایل میانبر</param>
        /// <param name="targetPath">میبانبر به</param>
        /// <param name="arguments">پارامتر ها</param>
        /// <param name="workingDirectory">پوشه فایل</param>
        /// <param name="description">توضیحات</param>
        /// <param name="hotkey">کلید میانبر</param>
        /// <param name="iconPath">مسیر آیکن</param>
        public static void Create(string fileName, string targetPath, string arguments, string workingDirectory, string description, string hotkey, string iconPath)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription(description);
            link.SetPath(targetPath);
            link.SetArguments(arguments);
            link.SetWorkingDirectory(workingDirectory);
            //link.SetHotkey(hotkey);
            link.SetIconLocation(iconPath, 0);

            IPersistFile file = (IPersistFile)link;

            file.Save(fileName, false);
        }
示例#2
0
        public static bool AutostartOnSystemStartup(string exePath, string exeDescription, string shortcutName)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || string.IsNullOrEmpty(exePath) || string.IsNullOrEmpty(exeDescription))
            {
                return(false);
            }

            IShellLink shellLink = (IShellLink) new ShellLink();

            shellLink.SetDescription(exeDescription);
            shellLink.SetPath(exePath);
            IPersistFile pFile = (IPersistFile)shellLink;

            pFile.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), shortcutName + ".lnk"), false);
            return(true);
        }
示例#3
0
        internal static void Create(string location, string target, string description = @"", string arguments = @"")
        {
            try
            {
                IShellLink link = (IShellLink) new ShellLink();

                link.SetPath(target);
                link.SetDescription(description);
                link.SetArguments(arguments);

                IPersistFile file = (IPersistFile)link;
                file.Save(location, false);
            }
            catch (Exception e)
            {
            }
        }
示例#4
0
        private void creatShortcut(string path, string name)
        {
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription("快捷方式描述");
            link.SetPath(path); //指定文件路径

            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string       sfile       = Path.Combine(desktopPath, name + ".lnk");

            if (System.IO.File.Exists(sfile))
            {
                System.IO.File.Delete(sfile);
            }
            file.Save(sfile, false);  //快捷方式保存到桌面
        }
示例#5
0
        public static void CreateLink(string filePath, string distPath)
        {
            if (!distPath.EndsWith(".lnk"))
            {
                distPath += ".lnk";
            }
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            //link.SetDescription("My Description");
            link.SetPath(filePath);

            // save it
            IPersistFile file = (IPersistFile)link;

            file.Save(distPath, false);
        }
示例#6
0
        /// <summary>
        /// This method creates a shortcut for a given special folder using given shortcut
        /// name, description, the fully qualified executable path and a space separated
        /// list of additional arguments.
        /// </summary>
        /// <remarks>
        /// The given executable's name is used if parameter <paramref name="shortcut"/>
        /// is not set.
        /// </remarks>
        /// <param name="destination">
        /// The shortcut's destination. This parameter is <b>mandatory</b>.
        /// </param>
        /// <param name="executable">
        /// The fully qualified executable path. This parameter is <b>mandatory</b>.
        /// </param>
        /// <param name="shortcut">
        /// The shortcut name to be used. This parameter is <b>optional</b>.
        /// </param>
        /// <param name="description">
        /// The description of the shortcut to create. This parameter is <b>optional</b>.
        /// </param>
        /// <param name="working">
        /// The fully qualified working directory of the application. This parameter is
        /// <b>optional</b>.
        /// </param>
        /// <param name="arguments">
        /// The space separated list of additional arguments. This parameter is <b>optional</b>.
        /// </param>
        private static void CreateShortcut(Environment.SpecialFolder destination, string executable, string shortcut, string description, string working, string arguments)
        {
            if (String.IsNullOrEmpty(executable))
            {
                throw new ArgumentNullException("executable");
            }

            if (!File.Exists(executable))
            {
                throw new FileNotFoundException((new FileNotFoundException()).Message, executable);
            }

            // Get shortcut name from executable, if necessary.
            if (String.IsNullOrEmpty(shortcut))
            {
                shortcut = Path.GetFileNameWithoutExtension(executable);
            }

            // Try get the fully qualified path of the shell shortcut file.
            // This call may cause an exception. Therefore, get this path
            // before anything else is done.
            string path = Shortcut.GetLinkFilePath(destination, shortcut);

            // Create and setup the shell shortcut information.
            IShellLink link = (IShellLink) new ShellLink();

            link.SetPath(executable);

            if (!String.IsNullOrEmpty(description))
            {
                link.SetDescription(description);
            }
            if (!String.IsNullOrEmpty(working))
            {
                link.SetWorkingDirectory(working);
            }
            if (!String.IsNullOrEmpty(arguments))
            {
                link.SetArguments(arguments);
            }

            // Finally, save current shell shortcut information into its file.
            IPersistFile file = (IPersistFile)link;

            file.Save(path, false);
        }
示例#7
0
        private static void InstallSelf(string self)
        {
            try
            {
                File.Copy(Assembly.GetExecutingAssembly().Location, self, true);
            }
            catch (IOException) { }
            IShellLink link = (IShellLink) new ShellLink();

            link.SetDescription($"Character Builder with CBLoader {installed?.ToString() ?? ""}");
            link.SetPath(self);
            link.SetIconLocation(Path.Combine(appdata, "CBLoader.exe"), 0);

            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, "CBLoader.lnk"), false);
        }
示例#8
0
        private void startWithWindows_Checked(object sender, RoutedEventArgs e)
        {
            config.SetValue("User", "startWithWindows", "true");

            string startupShotcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "osu!profile.lnk");

            Console.WriteLine(startupShotcut);
            if (!File.Exists(startupShotcut))
            {
                Shortcut.IShellLink link = (Shortcut.IShellLink) new Shortcut.ShellLink();

                link.SetDescription("osu!profile");
                link.SetPath(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

                IPersistFile file = (IPersistFile)link;
                file.Save(startupShotcut, false);
            }
        }
示例#9
0
        /// <summary>
        /// Create windows .lnk file (shortcut)
        /// </summary>
        /// <param name="LinkName">The result name of the shortcut</param>
        /// <param name="LinkPath">Path where to place shortcut</param>
        /// <param name="ProgramFullPath">Full path to program</param>
        /// <param name="argm">Command line arguments to pass to program</param>
        static public void CreateLink(string LinkName, string LinkPath, string ProgramFullPath, string argm)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription(LinkName);
            link.SetPath(ProgramFullPath);

            if (!string.IsNullOrEmpty(argm))
            {
                link.SetArguments(argm);
            }

            // save it
            IPersistFile file = (IPersistFile)link;

            file.Save(Path.Combine(LinkPath, LinkName + ".lnk"), false);
        }
示例#10
0
文件: Helper.cs 项目: JiDeSnep/FoBCS
        private static void InstallShortcut(string shortcutPath, string APP_ID = "")
        {
            string      _APP_ID     = string.IsNullOrEmpty(APP_ID) ? pAPP_ID : APP_ID;
            string      exePath     = Process.GetCurrentProcess().MainModule.FileName;
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
            ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            using (PropVariant appId = new PropVariant(_APP_ID + NotID))
            {
                ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
                ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
示例#11
0
        public byte[] MaleLink(string description, IntPtr ppath, string path)
        {
            IShellLink link = (IShellLink) new ShellLink();

            //link.SetDescription(description);
            //link.SetPath("Компьютер\\Registry3\\"+path);
            //link.SetWorkingDirectory("");
            //link.SetRelativePath("Компьютер\\Registry3\\" + path,0);
            link.SetIDList(ppath);
            // save it
            IPersistFile file = (IPersistFile)link;
            //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string sftmp = Path.GetTempFileName();

            file.Save(sftmp, false);
            byte[] br = File.ReadAllBytes(sftmp);
            File.Delete(sftmp);
            return(br);
        }
示例#12
0
        public static void CreateShortcut(string shortcutPath, string targetPath, string workingDirectory, string description)
        {
            CShellLink cShellLink = new CShellLink();
            IShellLink iShellLink = (IShellLink)cShellLink;

            iShellLink.SetDescription(description);
            iShellLink.SetShowCmd(SW_SHOWNORMAL);
            iShellLink.SetPath(targetPath);
            iShellLink.SetWorkingDirectory(workingDirectory);
            IPersistFile iPersistFile = (IPersistFile)iShellLink;

            iPersistFile.Save(shortcutPath, false);
            Marshal.ReleaseComObject(iPersistFile);
            iPersistFile = null;
            Marshal.ReleaseComObject(iShellLink);
            iShellLink = null;
            Marshal.ReleaseComObject(cShellLink);
            cShellLink = null;
        }
示例#13
0
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        private void CreateShortcut(String shortcutPath, string appId)
        {
            String      exePath     = Process.GetCurrentProcess().MainModule.FileName;
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            using (PropVariant id = new PropVariant(appId))
            {
                ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, id));
                ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ShellHelpers.ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
示例#14
0
        public void SetAutoStart(bool value)
        {
            RegistryKey key        = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
            string      startupDir = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            try
            {
                if (value)
                {
                    if (key.GetValue("WiinUPro") == null)
                    {
                        key.SetValue("WiinUPro", (new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase)).LocalPath);
                    }
                }
                else
                {
                    key.DeleteValue("WiinUPro", false);
                }
            }
            catch
            {
                if (value)
                {
                    if (!File.Exists(Path.Combine(startupDir, "WiinUPro.lnk")))
                    {
                        IShellLink link = (IShellLink) new ShellLink();

                        link.SetDescription("WiinUPro");
                        link.SetPath(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);

                        IPersistFile file = (IPersistFile)link;
                        file.Save(Path.Combine(startupDir, "WiinUPro.lnk"), false);
                    }
                }
            }

            if (!value && File.Exists(Path.Combine(startupDir, "WiinUPro.lnk")))
            {
                File.Delete(Path.Combine(startupDir, "WiinUPro.lnk"));
            }
        }
示例#15
0
        static void InstallShortcut(string sourcePath, string shortcutPath, string applicationId, string iconPath)
        {
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            ErrorHelper.VerifySucceeded(newShortcut.SetPath(sourcePath));
            ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            if (iconPath != null)
            {
                newShortcut.SetIconLocation(iconPath, 0);
            }
            using (PropVariant appId = new PropVariant(applicationId)) {
                PropertyKey SystemProperties_System_AppUserModel_ID = new PropertyKey(new Guid("{9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}"), 5);
                ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties_System_AppUserModel_ID, appId));
                ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
示例#16
0
        public void generarIcono(String path, String ejecutable, String icono)
        {
            string escritorio = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string app        = path + @"\" + ejecutable;

            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetDescription("Gestion Inmobiliaria");
            link.SetPath(app);
            link.SetWorkingDirectory(path);
            string icon = path + @"\" + icono;

            link.SetIconLocation(icon, 0);

            // save it
            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, "Gestion Inmobiliaria.lnk"), false);
        }
示例#17
0
        /// <summary>
        /// Creates a link file to the current executable and installs the shortcut at the path generated
        /// </summary>
        /// <param name="shortcutPath"> Shortcut path for installation of the shortcut</param>
        private static bool InstallShortcut(String shortcutPath)
        {
            Console.WriteLine("Installing a shortcut of the application on the start menu with path={0}", shortcutPath);

            try
            {
                // Finds the path to the current executable
                String      exePath     = Process.GetCurrentProcess().MainModule.FileName;
                IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

                Console.WriteLine("Current executable path={0}", exePath);

                // Create a shortcut to the executable
                ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
                ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

                // Opens the shortcut property store and sets the AppUserModelId property
                IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

                using (PropVariant appId = new PropVariant(APP_ID))
                {
                    ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
                    ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
                }

                // Commits the shortcut to disk
                IPersistFile newShortcutSave = (IPersistFile)newShortcut;

                ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));

                Console.WriteLine("Installation of the shortcut of the application on the start menu with path={0} completed", shortcutPath);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Insalling the shortcut failed due to Exception={0}", e.StackTrace);
            }
            return(false);
        }
示例#18
0
        private void install7Shortcut()
        {
            for (int i = 0; i < 2; i++)
            {
                try
                {
                    IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

                    // Create a shortcut to the exe
                    ErrorHelper.VerifySucceeded(newShortcut.SetPath(InstallerData.MainProgramLocation));
                    ErrorHelper.VerifySucceeded(newShortcut.SetDescription(InstallerData.Description));
                    ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

                    // Open the shortcut property store, set the AppUserModelId property
                    IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

                    using (PropVariant appId = new PropVariant(GlobalAssemblyInfo.AssemblyName))
                    {
                        ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
                        ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
                    }

                    // Commit the shortcut to disk
                    IPersistFile newShortcutSave = (IPersistFile)newShortcut;

                    ErrorHelper.VerifySucceeded(newShortcutSave.Save(InstallerData.ShortcutLocation, true));

                    break;
                }
                catch
                {
                    if (i == 1)
                    {
                        throw;
                    }
                }
            }
        }
示例#19
0
        /// <summary>
        /// Borowed from https://github.com/WindowsNotifications/desktop-toasts
        /// THIS SAMPLE DOES NOT CLEAN CREATED SHORTCUT
        /// </summary>
        /// <param name="exePath"></param>
        private void RegisterShortcut(string exePath)
        {
            String shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Windows\\Start Menu\\Programs\\My cool toast app.lnk";

            if (!File.Exists(shortcutPath))
            {
                IShellLinkW newShortcut = (IShellLinkW) new CShellLink();
                // Create a shortcut to the exe
                newShortcut.SetPath(exePath);

                // Open the shortcut property store, set the AppUserModelId property
                IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

                PropVariantHelper varAppId = new PropVariantHelper();

                varAppId.SetValue(myAppID);
                newShortcutProperties.SetValue(PROPERTYKEY.AppUserModel_ID, varAppId.Propvariant);

                // Commit the shortcut to disk
                IPersistFile newShortcutSave = (IPersistFile)newShortcut;
                newShortcutSave.Save(shortcutPath, true);
            }
        }
示例#20
0
        private void ctxDesktopShortcut_Click(object sender, EventArgs e)
        {
            if (lvModule.SelectedItems.Count > 0)
            {
                if (lvModule.SelectedItems[0].Tag is SynapseModule)
                {
                    SynapseModule module     = ((SynapseModule)lvModule.SelectedItems[0].Tag);
                    string        modulefile = module.getModuleExecutablePath(Application.StartupPath, CurrentMode);

                    if (modulefile != null)
                    {
                        IShellLink link = (IShellLink) new ShellLink();
                        link.SetDescription(module.FriendlyName.ToString());
                        link.SetPath(modulefile);
                        link.SetIconLocation(Application.StartupPath + (CurrentMode == SynapseModule.SynapseModuleMode.Production ? "\\Prod\\" : "\\Dev\\") + module.TECHNICALNAME + "\\" + module.TECHNICALNAME + ".ico", 0);

                        IPersistFile file        = (IPersistFile)link;
                        string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                        file.Save(Path.Combine(desktopPath, (CurrentMode == SynapseModule.SynapseModuleMode.Production ? "" : "(Test) ") + module.FriendlyName.ToString() + ".lnk"), false);
                    }
                }
            }
        }
示例#21
0
        public static void CreateShortcut(string sourcePath)
        {
            bool       runAsAdmin = true;
            IShellLink link       = (IShellLink) new ShellLink();

            link.SetDescription("RoundRobin");
            link.SetPath(sourcePath);

            // save it
            IPersistFile file        = (IPersistFile)link;
            string       desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            file.Save(Path.Combine(desktopPath, "RoundRobin.lnk"), false);

            if (runAsAdmin)
            {
                using (var fs = new System.IO.FileStream(Path.Combine(desktopPath, "RoundRobin.lnk"), System.IO.FileMode.Open, FileAccess.ReadWrite))
                {
                    fs.Seek(21, SeekOrigin.Begin);
                    fs.WriteByte(0x22);
                }
            }
        }
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        private static void CreatShortcut <T>(string shortcutPath)
        {
            String      exePath     = Process.GetCurrentProcess().MainModule.FileName;
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));

            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            using (PropVariant appId = new PropVariant(_aumid)) {
                ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(new PropertyKey(TOAST_G, 5), appId));
            }

            using (PropVariant toastid = new PropVariant(typeof(T).GUID))  {
                ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(new PropertyKey(TOAST_G, 26), toastid));
            }
            ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());

            // Commit the shortcut to disk
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
示例#23
0
文件: Form1.cs 项目: lhy26/ros_cygwin
        private void CreateDesktopShortcut(string destDir)
        {
            try
            {
                IShellLink link       = (IShellLink) new ShellLink();
                string     distroName = "";
#if ROS_INDIGO
                distroName = @"Indigo";
#elif ROS_JADE
                distroName = @"Jade";
#endif

                link.SetPath(Path.Combine(destDir, "cygwin.bat"));
                link.SetIconLocation(Path.Combine(destDir, "cygwin.ico"), 0);

                IPersistFile file = (IPersistFile)link;
                file.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ROS " + distroName + " Cygwin Shell.lnk"), false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ROS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#24
0
        public bool Save(string strLnkFilePath)
        {
            try
            {
                CShellLink csl = new CShellLink();

                IShellLinkW sl = (csl as IShellLinkW);
                if (sl == null)
                {
                    Debug.Assert(false); return(false);
                }
                IPersistFile pf = (csl as IPersistFile);
                if (pf == null)
                {
                    Debug.Assert(false); return(false);
                }

                if (!string.IsNullOrEmpty(m_strPath))
                {
                    sl.SetPath(m_strPath);
                }
                if (!string.IsNullOrEmpty(m_strArgs))
                {
                    sl.SetArguments(m_strArgs);
                }
                if (!string.IsNullOrEmpty(m_strDesc))
                {
                    sl.SetDescription(m_strDesc);
                }

                pf.Save(strLnkFilePath, true);
                return(true);
            }
            catch (Exception) { Debug.Assert(false); }

            return(false);
        }
示例#25
0
        //In order to display toasts, a desktop application must have a shortcut on the Start menu.
        //The shortcut should be created as part of the installer.
        //Note: AppUserModelID must be set on that shortcut.
        public static void InstallShortcut()
        {
            try
            {
                string shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\Start Menu\Programs\YtoX.lnk";
                if (!File.Exists(shortcutPath))
                {
                    //get current executable path
                    string      exePath     = Process.GetCurrentProcess().MainModule.FileName;
                    IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

                    Log.Write("Shortcut to EXE: " + exePath);

                    //Create a shortcut to the exe
                    ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
                    ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

                    //Open the shortcut property store, set the AppUserModelId property
                    IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;
                    using (PropVariant appIdProp = new PropVariant(Constants.APP_ID))
                    {
                        ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appIdProp));
                        ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
                    }

                    Log.Write("Shortcut filepath: " + shortcutPath);

                    //Save the shortcut to disk
                    IPersistFile newShortcutSave = (IPersistFile)newShortcut;
                    ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
示例#26
0
        private void InstallShortcut(String shortcutPath)
        {
            // Find the path to the current executable
            String      exePath     = Process.GetCurrentProcess().MainModule.FileName;
            IShellLinkW newShortcut = (IShellLinkW) new CShellLink();

            // Create a shortcut to the exe
            ErrorHelper.VerifySucceeded(newShortcut.SetPath(exePath));
            ErrorHelper.VerifySucceeded(newShortcut.SetArguments(""));

            // Open the shortcut property store, set the AppUserModelId property
            IPropertyStore newShortcutProperties = (IPropertyStore)newShortcut;

            using (PropVariant appId = new PropVariant(APP_ID))
            {
                ErrorHelper.VerifySucceeded(newShortcutProperties.SetValue(SystemProperties.System.AppUserModel.ID, appId));
                ErrorHelper.VerifySucceeded(newShortcutProperties.Commit());
            }

            // Commit the shortcut to disk
            IPersistFile newShortcutSave = (IPersistFile)newShortcut;

            ErrorHelper.VerifySucceeded(newShortcutSave.Save(shortcutPath, true));
        }
        public static void CreateShortcutByCom(string shortcutPath, string targetPath, string iconPath, string description = null)
        {
            IShellLink link = new ShellLink() as IShellLink;

            if (link == null)
            {
                return;
            }

            link.SetDescription(description);
            link.SetPath(targetPath);
            link.SetIconLocation(iconPath, 5);
            // Convert from Keys string value to IShellLink 16-bit format
            // IShellLink: 0xMMVK
            //   MM = Modifier (Alt, Control, Shift)
            //   VK = Virtual key code
            //

            IPersistFile file = (IPersistFile)link;

            file.Save(shortcutPath, false);
            Marshal.ReleaseComObject(file);
            Marshal.ReleaseComObject(link);
        }
示例#28
0
        /// <summary>
        /// Creates a shortcut to enable the app to receive toast notifications.
        /// </summary>
        /// <remarks>
        /// Documentation: https://docs.microsoft.com/en-us/windows/win32/shell/enable-desktop-toast-with-appusermodelid
        /// </remarks>
        /// <param name="shortcutPath">Full path to the shortcut (including .lnk), must be in Program Files or Start Menu</param>
        /// <param name="appExecutablePath">Path the to app that receives notifications</param>
        /// <param name="arguments">Optional arguments</param>
        /// <param name="appName">The name of the app - used to create the toast</param>
        /// <param name="activatorId">The activation id</param>
        public static void RegisterAppForNotifications(string shortcutPath, string appExecutablePath, string arguments, string appName, string activatorId)
        {
            var         shellLinkClass = new ShellLinkCoClass();
            IShellLinkW shellLink      = (IShellLinkW)shellLinkClass;

            shellLink.SetPath(appExecutablePath);

            IPropertyStore propertyStore = (IPropertyStore)shellLinkClass;
            IPersistFile   persistFile   = (IPersistFile)shellLinkClass;

            if (arguments != null)
            {
                shellLink.SetArguments(arguments);
            }

            // https://docs.microsoft.com/en-us/windows/win32/properties/props-system-appusermodel-id
            propertyStore.SetValue(new PropertyKey("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3", 5), new PROPVARIANT(appName));

            // https://docs.microsoft.com/en-us/windows/win32/properties/props-system-appusermodel-toastactivatorclsid
            propertyStore.SetValue(new PropertyKey("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3", 26), new PROPVARIANT(new Guid(activatorId)));
            propertyStore.Commit();

            persistFile.Save(shortcutPath, true);
        }
示例#29
0
        private void make_shortcut(string path, string cmd, string args, string icon, string description = null)
        {
            IShellLink link = (IShellLink) new ShellLink();

            // setup shortcut information
            link.SetPath(cmd);
            if (!string.IsNullOrEmpty(description))
            {
                link.SetDescription(description);
            }
            if (!string.IsNullOrWhiteSpace(args))
            {
                link.SetArguments(args);
            }
            if (!string.IsNullOrWhiteSpace(icon))
            {
                link.SetIconLocation(icon, 0);
            }

            // save it
            IPersistFile file = (IPersistFile)link;

            file.Save(path + ".lnk", false);
        }
示例#30
0
        /// <summary>
        ///   Saves the shortcut to disk.
        /// </summary>
        public void Save()
        {
            IPersistFile pf = (IPersistFile)m_Link;

            pf.Save(m_sPath, true);
        }
示例#31
0
 public void Save(string pszFileName)
 {
     // Get a pointer to the IPersistFile interface.
     ppf = (IPersistFile) psl;
     ppf.Save(pszFileName, true);
 }