/////===== Начало - ExecAndWait =====\\\\\
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
type
HINSTANCE = THandle;
var
lastproc: cardinal;
const
NORMAL_PRIORITY_CLASS = $00000020;
REALTIME_PRIORITY_CLASS = $00000100;
type
_TStartupInfo = record
cb: DWORD;
lpReserved, lpDesktop: Longint;
lpTitle: PAnsiChar;
dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags: DWORD;
wShowWindow, cbReserved2: Word;
lpReserved2: Byte;
hStdInput, hStdOutput, hStdError: Longint;
end;
_TProcessInformation = record
hProcess, hThread: Longint;
dwProcessId, dwThreadId: DWORD;
end;
_TMsg = record
hWnd: HWND;
msg, wParam: Word;
lParam: LongWord;
Time: TFileTime;
pt: TPoint;
end;
function OpenProcess(dwDesiredAccess: DWORD; bInheritHandle: BOOL; dwProcessId: DWORD): THandle; external 'OpenProcess@kernel32.dll stdcall';
function CloseHandle(hObject: THandle): BOOL; external 'CloseHandle@kernel32.dll stdcall';
procedure GetStartupInfo(var lpStartupInfo: _TStartupInfo); external 'GetStartupInfoA@kernel32.dll stdcall';
function CreateProcess(lpApplicationName: PAnsiChar; lpCommandLine: PAnsiChar; lpProcessAttributes, lpThreadAttributes: DWORD; bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: PAnsiChar; lpCurrentDirectory: PAnsiChar; const lpStartupInfo: _TStartupInfo; var lpProcessInformation: _TProcessInformation): BOOL; external 'CreateProcessA@kernel32.dll stdcall';
function WaitForSingleObject(hHandle: Longint; dwMilliseconds: DWORD): DWORD; external 'WaitForSingleObject@kernel32.dll stdcall';
function PeekMessage(var lpMsg: _TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): BOOL; external 'PeekMessageA@user32.dll stdcall';
function TranslateMessage(const lpMsg: _TMsg): BOOL; external 'TranslateMessage@user32.dll stdcall';
function DispatchMessage(const lpMsg: _TMsg): Longint; external 'DispatchMessageA@user32.dll stdcall';
function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string; lpParameters: string; lpDirectory: string; nShowCmd: Integer): HINSTANCE; external 'ShellExecute{#AW}@shell32.dll stdcall';
procedure Application_ProcessMessages;
var
Msg: _TMsg;
begin
while PeekMessage(Msg, 0, 0, 0, 1) do begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
function ExecAndWait(filename, params: pansichar; showcmd: integer; Wait: boolean; Priority: Smallint): Boolean;
var
SI : _TStartupInfo;
PI : _TProcessInformation;
CMD: string;
prt: DWORD;
begin
if RegKeyExists(HKLM,'SOFTWARE\WinRAR') or RegKeyExists(HKLM64,'SOFTWARE\WinRAR') then
begin
Result:=false;
CMD:='{app}\WinRarInstall.exe' + filename + '"' + params;
GetStartupInfo(SI);
SI.wShowWindow := showcmd;
SI.dwFlags := 1;
if Priority = 0 then prt:= NORMAL_PRIORITY_CLASS else
if Priority = 1 then prt:= REALTIME_PRIORITY_CLASS;
Result:=CreateProcess('', PansiChar(CMD), 0, 0, false, prt,'', pansichar(ExtractFilePath(filename)), SI, PI);
lastproc:=PI.dwProcessId;
if wait then
while WaitforSingleObject(PI.hProcess, 50) = $00000102 do
CloseHandle(PI.hProcess);
end;
end;
/////===== Конец - ExecAndWait =====\\\\\