Win32API: how to create a shortcut (.lnk file)

2019-07-25 17:53发布

问题:

I'm a Java developer, so please excuse my ignorance.

I want to create a shortcut to an executable, e.g., in the user's autostart or send-to folder (I don't want an installer to do that, because the installer usually is run by an administrator). What API (C preferred) I could use for that task (maybe using JNA)? Thanks in advance.

回答1:

As @Hans indicated, it requires COM (via ShellLinkObject or WScript.Shell). In Java you can call COM objects using a Java to COM bridge. There are a few available, ranging from free to commercial. A couple that I know of are:

  • Java2COM
  • JACOB
  • JCOM


回答2:

It requires using COM, ShellLinkObject from shell32.dll. No idea what that takes in Java, but you'll find C# code in my answer in this thread.