I want to create a shortcut pointing to some EXE file, on the desktop, using .NET Framework 3.5 and relying on an official Windows API. How can I do that?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
With additional options such as hotkey, description etc.
At first, Project > Add Reference > COM > Windows Script Host Object Model.
I use "Windows Script Host Object Model" reference to create shortcut.
and to create shortcut on specific location:
EDIT: I do not recommend this solution anymore. If there's still no better method than using the Windows scripting engine, at least use @Mehmet's solution which calls the engine directly rather than creating a plain text script in memory.
We used VBScript to generate a shortcut. It does not need p/Invoke, COM Interop and additional DLLs. It works like this:
Here you go:
Here's a (Tested) Extension Method, with comments to help you out.
And an example of use:
1st parm sets the exe name (found in the current directory) 2nd parm is the "Start In" folder and 3rd parm is the shortcut description.
The naming convention of the link leaves no ambiguity as to what it will do. To test the link just double click it.
Final Note: the application itself (target) must have an ICON image associated with it. The link is easily able to locate the ICON within the exe. If the target application has more than one icon, you may open the link's properties and change the icon to any other found in the exe.
You can use this ShellLink.cs class to create the shortcut.
To get the desktop directory, use:
or use
Environment.SpecialFolder.CommonDesktopDirectory
to create it for all users.