Execute / Shell

How do you get one program to start another?

Visual Basic | Delphi | JavaScript | Windows API


Visual Basic 6.0


Delphi 5.0

Searching the Delphi 5 help provided no clues at all. I had to use the Windows SDK help to find the examples below.


ShellExecute

In order to use ShellExecute and ShellExecuteEx, you must include ShellAPI in the uses clause.
  ShellExecute(Self.Handle, nil, 'notepad.exe', nil, nil, SW_SHOWNORMAL);

var           
  temp: string;
  A: array[0..300] of Char;
begin
  temp := 'path\ComponentHelp.html';
  StrPCopy(A, temp);
  ShellExecute(Self.Handle, nil, a, nil, nil, SW_SHOWNORMAL);
end;

There are 12 possible constants for nShowCmd, though several of them are assigned the same value. To use them, you must also include windows in the uses clause. This is just a sample.


WinExec

This is the simplest method I've found - but the help says that it is only "provided for compatibility with earlier versions of Windows". Instead, you should use CreateProcess.


CreateProcess

According to the help, CreateProcess replaces WinExec and LoadModule.

CreateProcess is a pain - It took me several hours to get only basic functionality. (There are no examples in the help.)


JavaScript

So far, all attempts to use JavaScript to start another application have failed using IE 6.0 ... inspite of several examples. This is some of what I tried.

In test_me, whenever I comment out the obShell.ShellExecute commands, the Alert command opens a dialog box. When any one of those commands is present, clicking jstest opens a new browser window. I am assuming that this indicates some kind of programming error since return false; in the a-link (which is supposed to stop the link from opening) is apparently not being executed.

vbtest fails in the same manner.

References:


Windows API


ExecProgram

ExecProgram is a macro defined in the Win32 Developer's Reference supplied with Delphi 5. However, there was no way to get it to work with Delphi 5. The supported display-state values are


ShellExecute and ShellExecuteEx

ShellExecuteEx requires that you build a record first.


WinExec

CreateProcess replaces WinExec and LoadModule


CreateProcess

CreateProcess replaces WinExec and LoadModule


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / Execute_Shell.htm