Home >Backend Development >C++ >How Can I Programmatically Create Application Shortcuts in Specific Directories Using C#?

How Can I Programmatically Create Application Shortcuts in Specific Directories Using C#?

Susan Sarandon
Susan SarandonOriginal
2025-01-14 10:01:43453browse

How Can I Programmatically Create Application Shortcuts in Specific Directories Using C#?

Use C# to create application shortcuts in the specified directory

How to create application shortcuts using .lnk files:

In C#, application shortcuts (.lnk files) can be easily created using the .NET framework. These shortcuts provide quick access to an application or URL by generating a .lnk file pointing to the target.

Implementation method:

Custom application shortcuts require a special class called ShellLink.cs, which comes from vbAccelerator. This class uses interop and does not rely on WSH, ensuring seamless implementation.

Shortcut creation sample code:

<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>

Code description:

This code is responsible for creating a shortcut in the specified directory. It specifies the target application's path, working directory, description, display mode, and path to the shortcut file (STARTUP_SHORTCUT_FILEPATH).

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

Statement:
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