Launch Applications and Files
We frequently need to launch some applications and files from our Delphi applications. To do this, we can use ShellExecute() function (check out the Delphi documentation for full description of parameters and error codes returned). Remember that we must use ShellAPI unit in your Delphi source code.
Let's see some examples of ShellExecute() function:
// Launch Notepad.exe ShellExecute( Handle, 'open', 'c:\windows\notepad.exe', nil, nil, SW_SHOWNORMAL ); // Launch Notepad.exe to open readme.txt ShellExecute( Handle, 'open', 'c:\windows\notepad.exe', 'c:\readme.txt', nil, SW_SHOWNORMAL ); // Open C:\Download folder ShellExecute( Handle, 'open', 'c:\download', nil, nil, SW_SHOWNORMAL ); // Open Word document ShellExecute( Handle, 'open', 'c:\docs\letter.doc', nil, nil, SW_SHOWNORMAL ); // Open a URL with the default Web Browser ShellExecute( Handle, 'open', 'http://hianoto.net', nil, nil, SW_SHOWNORMAL ); // Display a new e-mail with the default E-mail Client ShellExecute( Handle, 'open', PChar( 'mailto:hian@hianoto.net' ), nil, nil, SW_SHOWNORMAL );