I m looking for a way to improve the navigation between different tools (under windows). I would like to add in the body of an email a special "link" that when the user will click on it will launch my delphi app installed in his local computer. Is it possible and if yes how to do?
1 Answers
Yes, it is possible. Your application must create a moniker (for example, from its setup or first launch). This will allow the mail client to open an URL pointing to your application, and Windows will launch it and pass the URL to it.
Here is some source code to register/unregister the URL protocol:
function RegisterURLProtocol(
const ProtocolID : String;
const ProtocolName : String;
const DefaultIcon : String;
const OpenCommand : String) : Boolean;
var
Reg : TRegistry;
begin
Result := FALSE;
Reg := TRegistry.Create(KEY_WRITE);
try
Reg.RootKey := HKEY_CLASSES_ROOT;
if not Reg.OpenKey(ProtocolID, TRUE) then
Exit;
Reg.WriteString('', 'URL:' + ProtocolName);
Reg.WriteString('URL Protocol', '');
if Reg.OpenKey('DefaultIcon', True) then begin
Reg.WriteString('', DefaultIcon);
end;
Reg.CloseKey;
if not Reg.OpenKey(ProtocolID + '\shell\open\command', True) then
Exit;
Reg.WriteString('', OpenCommand);
Result := TRUE;
finally
FreeAndNil(Reg);
end;
end;
function UnregisterURLProtocol(
const ProtocolID : String) : Boolean;
var
Reg : TRegistry;
begin
Result := FALSE;
Reg := TRegistry.Create(KEY_WRITE);
try
Reg.RootKey := HKEY_CLASSES_ROOT;
if not Reg.KeyExists(ProtocolID) then
Exit;
Reg.DeleteKey(ProtocolID + '\DefaultIcon');
Reg.DeleteKey(ProtocolID + '\shell\open\command');
Reg.DeleteKey(ProtocolID + '\shell\open');
Reg.DeleteKey(ProtocolID + '\shell');
Reg.DeleteKey(ProtocolID);
Result := TRUE;
finally
FreeAndNil(Reg);
end;
end;
ProtocolID
is the identifier for your protocol. You can use something like 'MyApp'
. If you had to register the HTTP protocol, you would use 'http'
. The application will be opened by Windows when the user clicks on the link. The application will receive what is specified by the OpenCommand (A string you specify). You can include %1 in that OpenCommand and it will be replaced by the URL except the protocol.
ProtocolName
is a string describing your protocol.
The URL to place in the mail would be like this:
MyApp://SomeParameters/SomeMoreParameters

- 11,983
- 1
- 24
- 46
-
-
1
-
You should also include what such a URL would then have to look like when placed in the email. – Remy Lebeau Nov 17 '20 at 16:30
-
-
Also, you should add how the program would read the URL it is being launched with. – Remy Lebeau Nov 17 '20 at 17:11
-