Replies: 1 comment 3 replies
-
I was able to achieve this syntax and it ran successfully, so this is at least an option to consider: public static void CreateShortcut(string shortcutPath, string targetPath)
{
var shellLink = new IShellLinkW();
shellLink.SetPath(targetPath);
shellLink.SetWorkingDirectory(Path.GetDirectoryName(targetPath)!);
((IPersistFile)shellLink).Save(shortcutPath, fRemember: false);
} To make this work, all I had to do was apply [ComImport, Guid("00021401-0000-0000-C000-000000000046")]
// Only one or the other of these following attributes seems to be needed.
[ClassInterface(ClassInterfaceType.None)]
[TypeLibType(TypeLibTypeFlags.FCanCreate)]
internal class ShellLink { } The public static void CreateShortcut(string shortcutPath, string targetPath)
{
var shellLink = (IShellLinkW)new ShellLink();
shellLink.SetPath(targetPath);
shellLink.SetWorkingDirectory(Path.GetDirectoryName(targetPath)!);
((IPersistFile)shellLink).Save(shortcutPath, fRemember: false);
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Using 0.1.506-beta, I couldn't figure out how to use the generated
ShellLink
struct other than by stringing togetherActivator.CreateInstance
,Type.GetTypeFromCLSID
, andtypeof(ShellLink).GUID
. Is this the intended usage? Is nicer syntax thinkable?NativeMethods.txt
Utils.cs
ShellLink.g.cs contains:
Beta Was this translation helpful? Give feedback.
All reactions