PeterPanettone 158 Posted November 3, 2019 "A Shell link is a data object that contains information used to access another object in the Shell's namespace": Read the whole definition here: https://docs.microsoft.com/en-us/windows/win32/shell/links I was searching for a Delphi VCL library allowing me to easily create a Shell-Link with all properties described in the Microsoft documentation: https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllinkw I found a lot of libraries for this purpose, but most of them were outdated or had some flaws or bugs. Most of the libraries lacked the feature to create a Shell-Link with a Hotkey. The ShellBrowser Delphi VCL Library from JamSoftware contains a method to easily create a Shell-Link: https://www.jam-software.com/shellbrowser_delphi/index.shtml Unfortunately, it has no easy method to configure the properties (especially the hotkey property) of the newly created Shell-Link. Fortunately, the above mentioned Microsoft documentation provides all the information to succeed in the task: I use a standard THotKey control in the UI to allow the user to configure a hotkey for the newly created Shell-Link: The THotKey control has these main properties - HotKey and Modifiers: So the whole process of creating the Shell-Link with the Hotkey properties can be achieved with these steps: 1. Get the ItemIdList of the created Link: 2. Provide the IShellLink Interface of the ItemIdList: 3. Declare the IPersistFile interface for the Shell-Link file: 4. Now we need (as mentioned in the Microsoft documentation) to store the virtual key code in the low-order byte and the modifier flags in the high-order byte of the Shell-Link Hotkey property. For this purpose we declare a record containing two byte-fields: Then we get the Hotkey from the THotKey control, assign it to the record and typecast the record to a Word: But the Modifiers value is still missing from the record. So next, we get the Modifier-keys from the THotKey control and assign them to the Modifier Byte of the record: Now we can assign the record (again typecasted to a Word) to the Shell-Link interface: 5. The other Shell-Link properties are easy to set and are explained in the Microsoft documentation. 6. In the last step we can now save the configured Shell-Link: You can download the source code and learn from its implementation: ShellLinkShortcutTest.zip Here is a compiled exe demo of the program: ShellLinkShortcutTest_CompiledExeDemo.zip To compile the source code yourself you need the ShellBrowser library. You can download a free trial version here: https://customers.jam-software.de/shellbrowser_delphi/download.shtml?language=EN The many other features of the ShellBrowser library are explained here: https://www.jam-software.com/shellbrowser_delphi/features.shtml I am not affiliated with JamSoftware, but I recommend the ShellBrowser library as an excellent product. I wish you a lot of fun with this demo! 2 Share this post Link to post
Attila Kovacs 631 Posted November 3, 2019 https://www.tek-tips.com/faqs.cfm?fid=7526 ? Share this post Link to post
PeterPanettone 158 Posted November 3, 2019 2 minutes ago, Attila Kovacs said: https://www.tek-tips.com/faqs.cfm?fid=7526 ? When trying to open this link I got this error message: Share this post Link to post
Attila Kovacs 631 Posted November 3, 2019 They killed Kenny! Strange, I just opened it 5 minutes ago 😄 Try it later again, its a thin unit to do the same. (As I understand your needs) Share this post Link to post
Attila Kovacs 631 Posted November 3, 2019 https://web.archive.org/web/20171110112441/https://www.tek-tips.com/faqs.cfm?fid=7526 1 Share this post Link to post
PeterPanettone 158 Posted November 3, 2019 (edited) 48 minutes ago, Attila Kovacs said: https://web.archive.org/web/20171110112441/https://www.tek-tips.com/faqs.cfm?fid=7526 Compiler (Delphi 10.3.1 Rio) unfortunately found these errors in the code: [dcc32 Error] ShellLink.pas(93): E2188 Published property 'ItemIDList' cannot be of type POINTER [dcc32 Error] ShellLink.pas(274): E2033 Types of actual and formal var parameters must be identical [dcc32 Error] ShellLink.pas(337): E2033 Types of actual and formal var parameters must be identical [dcc32 Error] ShellLink.pas(338): E2033 Types of actual and formal var parameters must be identical Edited November 3, 2019 by PeterPanettone Share this post Link to post
Attila Kovacs 631 Posted November 3, 2019 (edited) And? Change Published to Public and TWin32FindDataA to TWin32FindDataW or TWin32FindData, Dummy: Longint to Dummy: Cardinal Edited November 3, 2019 by Attila Kovacs Share this post Link to post
PeterPanettone 158 Posted November 3, 2019 44 minutes ago, Attila Kovacs said: And? Unfortunately it does not work: Share this post Link to post
Attila Kovacs 631 Posted November 3, 2019 This is how I'm using it. SCut := TWin32ShortCut.Create; try SCut.Location := ciDesktop; SCut.FileName := sp[0]; SCut.AppPath := ResolvePath(sp[1]); SCut.WorkDir := ResolvePath(sp[2]); SCut.IconPath := ResolvePath(sp[3]); if l > 4 then if TryStrToInt(sp[4], i) then SCut.IconIndex := i; SCut.SaveShortCut; finally SCut.Free; end; function ResolvePath(const Path: string): string; var sp: TArray<string>; i: Integer; begin sp := Path.Split(['%']); Result := ''; for i := 0 to High(sp) do case i mod 2 of 0: Result := Result + sp[i]; 1: Result := Result + GetEnvironmentVariable(sp[i]); end; end; Share this post Link to post
PeterPanettone 158 Posted November 3, 2019 4 minutes ago, Attila Kovacs said: This is how I'm using it. Loading a Shell-Link and reading its properties does not work with the above code: Share this post Link to post
PeterPanettone 158 Posted November 3, 2019 2 hours ago, PeterPanettone said: I found a lot of libraries for this purpose, but most of them were outdated or had some flaws or bugs. Confirmed. Share this post Link to post
Attila Kovacs 631 Posted November 3, 2019 I'm not sure if you missed the second line in the code "shortcut creation object". I did not know that you want to edit existing shortcuts, sorry. 2 hours ago, PeterPanettone said: I was searching for a Delphi VCL library allowing me to easily create a Shell-Link with all properties described in the Microsoft documentation: I'm wasting here my time. Confirmed. Share this post Link to post
PeterPanettone 158 Posted November 3, 2019 2 minutes ago, Attila Kovacs said: I did not know that you want to edit existing shortcuts I just tried to use the linked unit. This has nothing to do with what I want. Sorry about that. Share this post Link to post