How was my Application launched?
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.
If you associated your application with a file extension, you can have paramcount=1 and you can read the opened file in paramstr(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.
The only way to do that is to have your app launched from a shortcut that passes command-line parameters to your app. Simply clicking on the file directly does not pass any parameters.