function Exec(Filename, Params:
String;
WindowState: Word = SW_SHOWNORMAL): boolean;
var
{$IFDEF UNICODE} ShExecInfoW: SHELLEXECUTEINFOW;
{$ENDIF}
ShExecInfoA: SHELLEXECUTEINFOA;
begin
Result := false;
if (Filename = '
')
or not FileExists(FileName)
then
exit;
{$IFDEF UNICODE}
if (Win32Platform = VER_PLATFORM_WIN32_NT)
then
begin
ShExecInfoW.Wnd := GetForegroundWindow;
ShExecInfoW.cbSize := SizeOf(SHELLEXECUTEINFOW);
ShExecInfoW.fMask := SEE_MASK_DEFAULT;
ShExecInfoW.lpVerb := '
open';
ShExecInfoW.lpFile := PWideChar(WideString(Filename));
ShExecInfoW.lpParameters := PWideChar(WideString(Params));
ShExecInfoW.lpDirectory := PWideChar(WideString(ExtractFileDir(Filename)));
ShExecInfoW.nShow := WindowState;
Result := ShellExecuteExW(@ShExecInfoW);
end
else
{$ENDIF}
begin
ShExecInfoA.Wnd := GetForegroundWindow;
ShExecInfoA.cbSize := sizeof(SHELLEXECUTEINFOA);
ShExecInfoA.fMask := SEE_MASK_DEFAULT;
ShExecInfoA.lpVerb := '
open';
ShExecInfoA.lpFile := PAnsiChar(AnsiString(Filename));
ShExecInfoA.lpParameters := PAnsiChar(AnsiString(Params));
ShExecInfoA.lpDirectory := PAnsiChar(AnsiString(ExtractFileDir(Filename)));
ShExecInfoA.nShow := WindowState;
Result := ShellExecuteExA(@ShExecInfoA);
end;
end;
//Aufruf:
Exec('
c:\test\test.lnk', '
', SW_MINIMIZE);
//startet ganz normal, d.h. Programmfenster ist nach dem Start sichtbar
Exec('
c:\test\test.lnk', '
', SW_SHOWMINNOACTIVE);
//startet das Programm minimiert, aber es treten die im ersten Post gezeigten Darstellungsfehler auf