Home > Backend Development > C++ > How to Programmatically Create Application Shortcuts in C#?

How to Programmatically Create Application Shortcuts in C#?

Mary-Kate Olsen
Release: 2025-01-14 06:29:46
Original
797 people have browsed it

How to Programmatically Create Application Shortcuts in C#?

Create application shortcuts in C# using ShellLink.cs

Question:

How to programmatically create application shortcuts (.lnk files) in C# using the .NET Framework?

Solution:

While there may not be a direct method, the ShellLink.cs class from vbAccelerator provides a powerful solution that does not rely on WSH.

Implementation:

Using this class you can create shortcuts as follows:

<code class="language-csharp">private static void configStep_addShortcutToStartupGroup()
{
    using (ShellLink shortcut = new ShellLink())
    {
        shortcut.Target = Application.ExecutablePath;
        shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
        shortcut.Description = "我的快捷方式名称";
        shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
        shortcut.Save(STARTUP_SHORTCUT_FILEPATH);
    }
}</code>
Copy after login

Advantages of ShellLink.cs:

  • Based on interoperability, no need to rely on WSH
  • Simplified the process of creating and configuring shortcuts

The above is the detailed content of How to Programmatically Create Application Shortcuts in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template