Exemple #1
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);
        }
Exemple #2
0
 /// <summary>
 /// This method removes the shortcut for the given shortcut name from the given
 /// special folder.
 /// </summary>
 /// <param name="destination">
 /// The shortcut's destination. This parameter is <b>mandatory</b>.
 /// </param>
 /// <param name="shortcut">
 /// The shortcut name to remove. This parameter is <b>mandatory</b>.
 /// </param>
 private static void RemoveShortcut(Environment.SpecialFolder destination, string shortcut)
 {
     // Try get the fully qualified path of the shell
     // shortcut file. This call may cause an exception.
     File.Delete(Shortcut.GetLinkFilePath(destination, shortcut));
 }
Exemple #3
0
 /// <summary>
 /// This method tries to determine if the given shortcut exists within the given
 /// special folder.
 /// </summary>
 /// <param name="destination">
 /// The shortcut's destination. This parameter is <b>mandatory</b>.
 /// </param>
 /// <param name="shortcut">
 /// The shortcut name to remove. This parameter is <b>mandatory</b>.
 /// </param>
 /// <returns>
 /// This method returns <c>true</c> if a shortcut exists for the combination of
 /// special folder and shortcut name and <c>false</c> otherwise.
 /// </returns>
 private static bool IsShortcut(Environment.SpecialFolder destination, string shortcut)
 {
     // Try get the fully qualified path of the shell
     // shortcut file. This call may cause an exception.
     return(File.Exists(Shortcut.GetLinkFilePath(destination, shortcut)));
 }
Exemple #4
0
 /// <summary>
 /// This method removes the shortcut for the current application from the user's
 /// <b>Desktop</b>.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used as default shortcut name.
 /// </remarks>
 public static void RemoveDesktopShortcut()
 {
     Shortcut.RemoveDesktopShortcut(Path.GetFileNameWithoutExtension(Application.ExecutablePath));
 }
Exemple #5
0
 /// <summary>
 /// This method removes the shortcut for the given shortcut name from the user's
 /// <b>Desktop</b>.
 /// </summary>
 /// <param name="shortcut">
 /// The shortcut name to be used. This parameter is <b>mandatory</b>.
 /// </param>
 public static void RemoveDesktopShortcut(string shortcut)
 {
     Shortcut.RemoveShortcut(Environment.SpecialFolder.DesktopDirectory, shortcut);
 }
Exemple #6
0
 /// <summary>
 /// This method creates a shortcut under the user's <b>Startup</b> menu using
 /// the given shortcut name.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used if parameter
 /// <paramref name="shortcut"/> is not set.
 /// </remarks>
 /// <param name="shortcut">
 /// The shortcut name to be used. This parameter is <b>optional</b>.
 /// </param>
 public static void CreateStartupShortcut(string shortcut)
 {
     Shortcut.CreateStartupShortcut(shortcut, String.Empty);
 }
Exemple #7
0
 /// <summary>
 /// This method creates a shortcut on the user's <b>Desktop</b> using given
 /// shortcut name, description, the fully qualified executable path, a space
 /// separated list of additional arguments as well as an application's working
 /// directory.
 /// </summary>
 /// <remarks>
 /// The given executable's name is used if parameter <paramref name="shortcut"/>
 /// is not set.
 /// </remarks>
 /// <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="executable">
 /// The fully qualified executable path. This parameter is <b>mandatory</b>.
 /// </param>
 /// <param name="arguments">
 /// The space separated list of additional arguments. 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>
 public static void CreateDesktopShortcut(string shortcut, string description, string executable, string arguments, string working)
 {
     Shortcut.CreateShortcut(Environment.SpecialFolder.DesktopDirectory, executable, shortcut, description, working, arguments);
 }
Exemple #8
0
 /// <summary>
 /// This method creates a shortcut on the user's <b>Desktop</b> using the given
 /// shortcut name.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used if parameter
 /// <paramref name="shortcut"/> is not set.
 /// </remarks>
 /// <param name="shortcut">
 /// The shortcut name to be used. This parameter is <b>optional</b>.
 /// </param>
 public static void CreateDesktopShortcut(string shortcut)
 {
     Shortcut.CreateDesktopShortcut(shortcut, String.Empty);
 }
Exemple #9
0
 /// <summary>
 /// This method creates a shortcut on the user's <b>Desktop</b> using given
 /// shortcut name and a description as well.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used if parameter
 /// <paramref name="shortcut"/> is not set.
 /// </remarks>
 /// <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>
 public static void CreateDesktopShortcut(string shortcut, string description)
 {
     Shortcut.CreateDesktopShortcut(shortcut, description, Application.ExecutablePath);
 }
Exemple #10
0
 /// <summary>
 /// This method tries to determine if the given shortcut name exists on the user's
 /// <b>Desktop</b>.
 /// </summary>
 /// <param name="shortcut">
 /// The shortcut name to be used. This parameter is <b>mandatory</b>.
 /// </param>
 /// <returns>
 /// This method returns <c>true</c> if the given shortcut name exists on the user's
 /// <b>Desktop</b> and <c>false</c> otherwise.
 /// </returns>
 public static bool IsDesktopShortcut(string shortcut)
 {
     return(Shortcut.IsShortcut(Environment.SpecialFolder.DesktopDirectory, shortcut));
 }
Exemple #11
0
 /// <summary>
 /// This method creates a shortcut on the user's <b>Desktop</b> using a default
 /// shortcut name.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used as default shortcut name.
 /// </remarks>
 public static void CreateDesktopShortcut()
 {
     Shortcut.CreateDesktopShortcut(String.Empty);
 }
Exemple #12
0
 /// <summary>
 /// This method removes the shortcut for the given shortcut name from the user's
 /// <b>Startup</b> menu.
 /// </summary>
 /// <param name="shortcut">
 /// The shortcut name to be used. This parameter is <b>mandatory</b>.
 /// </param>
 public static void RemoveStartupShortcut(string shortcut)
 {
     Shortcut.RemoveShortcut(Environment.SpecialFolder.Startup, shortcut);
 }
Exemple #13
0
 /// <summary>
 /// This method creates a shortcut under the user's <b>Startup</b> menu using
 /// given shortcut name, description, the fully qualified executable path, a
 /// space separated list of additional arguments as well as an application's
 /// working directory.
 /// </summary>
 /// <remarks>
 /// The given executable's name is used if parameter <paramref name="shortcut"/>
 /// is not set.
 /// </remarks>
 /// <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="executable">
 /// The fully qualified executable path. This parameter is <b>mandatory</b>.
 /// </param>
 /// <param name="arguments">
 /// The space separated list of additional arguments. 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>
 public static void CreateStartupShortcut(string shortcut, string description, string executable, string arguments, string working)
 {
     Shortcut.CreateShortcut(Environment.SpecialFolder.Startup, executable, shortcut, description, working, arguments);
 }
Exemple #14
0
 /// <summary>
 /// This method creates a shortcut under the user's <b>Startup</b> menu using
 /// given shortcut name, description as well as the fully qualified executable
 /// path.
 /// </summary>
 /// <remarks>
 /// The given executable's name is used if parameter <paramref name="shortcut"/>
 /// is not set.
 /// </remarks>
 /// <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="executable">
 /// The fully qualified executable path. This parameter is <b>mandatory</b>.
 /// </param>
 public static void CreateStartupShortcut(string shortcut, string description, string executable)
 {
     Shortcut.CreateStartupShortcut(shortcut, description, executable, String.Empty);
 }
Exemple #15
0
 /// <summary>
 /// This method tries to determine if a shortcut for the current application exists
 /// within the user's <b>Startup</b> menu.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used as default shortcut name.
 /// </remarks>
 /// <returns>
 /// This method returns <c>true</c> if the current application's shortcut exists
 /// within the <b>Startup</b> menu and <c>false</c> otherwise.
 /// </returns>
 public static bool IsStartupShortcut()
 {
     return(Shortcut.IsStartupShortcut(Path.GetFileNameWithoutExtension(Application.ExecutablePath)));
 }
Exemple #16
0
 /// <summary>
 /// This method creates a shortcut on the user's <b>Desktop</b> 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="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="executable">
 /// The fully qualified executable path. This parameter is <b>mandatory</b>.
 /// </param>
 /// <param name="arguments">
 /// The space separated list of additional arguments. This parameter is <b>optional</b>.
 /// </param>
 public static void CreateDesktopShortcut(string shortcut, string description, string executable, string arguments)
 {
     Shortcut.CreateDesktopShortcut(shortcut, description, executable, arguments, String.Empty);
 }
Exemple #17
0
 /// <summary>
 /// This method tries to determine if the given shortcut name exists within the
 /// user's <b>Startup</b> menu.
 /// </summary>
 /// <param name="shortcut">
 /// The shortcut name to be used. This parameter is <b>mandatory</b>.
 /// </param>
 /// <returns>
 /// This method returns <c>true</c> if the given shortcut name exists within the
 /// <b>Startup</b> menu and <c>false</c> otherwise.
 /// </returns>
 public static bool IsStartupShortcut(string shortcut)
 {
     return(Shortcut.IsShortcut(Environment.SpecialFolder.Startup, shortcut));
 }
Exemple #18
0
 /// <summary>
 /// This method creates a shortcut under the user's <b>Startup</b> menu using
 /// a default shortcut name.
 /// </summary>
 /// <remarks>
 /// The current application's executable name is used as default shortcut name.
 /// </remarks>
 public static void CreateStartupShortcut()
 {
     Shortcut.CreateStartupShortcut(String.Empty);
 }