ShellExecute example with complete return values

ShellExecute example with complete return values

procedure TForm1.Button1Click(Sender: TObject);
var
ErrorCode : Integer;
begin
ErrorCode := ShellExecute(0, ‘open’, pchar(‘c:\test.txt’), nil, nil, SW_NORMAL);
case ErrorCode of
2:ShowMessage(‘file not found’);
3:ShowMessage(‘path not found’);
5:ShowMessage(‘access denied’);
8:ShowMessage(‘not enough memory’);
32:ShowMessage(‘dynamic-link library not found’);
26:ShowMessage(‘sharing violation’);
27:ShowMessage(‘filename association incomplete or invalid’);
28:ShowMessage(‘DDE request timed out’);
29:ShowMessage(‘DDE transaction failed’);
30:ShowMessage(‘DDE busy’);
31:ShowMessage(‘no application associated with the given filename extension’);
end;

// You can also use the SysErrorMessage function to return the error message:
(*
// ReturnValue = Integer
ReturnValue := ShellExecute(0, ‘open’, ‘C:\test.txt’, nil, nil, SW_NORMAL);
if ReturnValue <= 32 then
ShowMessage(SysErrorMessage(ReturnValue));
// *)

{
SE_ERR_FNF = 2;
SE_ERR_PNF = 3;
SE_ERR_ACCESSDENIED = 5;
SE_ERR_OOM = 8;
SE_ERR_DLLNOTFOUND = 32;
SE_ERR_SHARE = 26;
SE_ERR_ASSOCINCOMPLETE = 27;
SE_ERR_DDETIMEOUT = 28;
SE_ERR_DDEFAIL = 29;
SE_ERR_DDEBUSY = 30;
SE_ERR_NOASSOC = 31;
}
end;