How can I identify if my Application was launched by the user? For example, if the Exe was double clicked, or right click > open from Windows Explorer.
I need a function to determine the above, something like:
function AppWasExecutedByUser: Boolean;
begin
//
end;
procedure TForm1.OnCreate(Sender: TObject);
begin
if AppWasExecutedByUser then
ShowMessage('User opened the exe by double clicking in Windows')
else
ShowMessage('Application was opened some other way');
end;
Appreciate your thoughts.
Thanks.
If you associated your application with a file extension, you can have
paramcount=1and you can read the opened file inparamstr(1).If you open the application itself, a double click or Open on the executable will have the same effect:
paramcount=0. In fact, the windows explorer is calling the ShellApi with the same parameters. So there is no way to identify it.And
paramstr(0)will always contain the full executable path, in both case.Even if you create a shortcut link, and add a parameter, double click or right click + Open will have the same result.