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;

procedure TForm1.OnCreate(Sender: TObject);
  if AppWasExecutedByUser then
    ShowMessage('User opened the exe by double clicking in Windows')
    ShowMessage('Application was opened some other way');

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.

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.