pokexperto1,
Cita:
Empezado por pokexperto1
...¿Validar ShellExecute con Try?...quiero saber si no lo ha conseguido abrir...
|
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellAPI;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
NameApp : PChar;
ErrMsg : Integer;
begin
NameApp := 'C:\Windows\System32\xNotepad.exe';
ErrMsg := ShellExecute(Handle, nil, NameApp, nil, nil, SW_SHOW);
if (ErrMsg <= 32) then
raise Exception.CreateFmt('ShellExecute Error %d : %s',[GetLastError,SysErrorMessage(GetLastError)]);
end;
end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32,
Levanta una excepción si la función ShellExecute devuelve un código de error, como se muestra en la siguiente imagen:
Revisa esta información:
Cita:
Empezado por Microsoft
ShellExecute function
Return value Type: HINSTANCE
If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.
Return codeDescription 0 : The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND : The specified file was not found.
ERROR_PATH_NOT_FOUND : The specified path was not found.
ERROR_BAD_FORMAT : The .exe file is invalid (non-Win32 .exe or error in .exe image).
SE_ERR_ACCESSDENIED : The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE : The file name association is incomplete or invalid.
SE_ERR_DDEBUSY : The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL : The DDE transaction failed.
SE_ERR_DDETIMEOUT : The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND : The specified DLL was not found.
SE_ERR_FNF : The specified file was not found.
SE_ERR_NOASSOC : There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM : There was not enough memory to complete the operation.
SE_ERR_PNF : The specified path was not found.
SE_ERR_SHARE : A sharing violation occurred.
Tomado de : ShellExecute function
|
Espero sea útil
Nelson.