var
ResultCode: Integer;
begin
// Launch Notepad and wait for it to terminate
if Exec(ExpandConstant('{win}\notepad.exe'), '', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
end
else begin
// handle failure if necessary; ResultCode contains the error code
end;
end;
这里需要注意变量ResultCode,它是通过引用传递给函数的,函数执行完毕后会写入完成代码。
标志ewWaitUntilTerminated强制等待被调用命令的完成。
以下是安装 MSI 软件包的示例:
procedure InstallMsi(FilePath, InstallFolderPath: string; var RebootRequired: boolean);
var
ResultCode: integer;
begin
Exec('msiexec.exe', '/quiet /i "' + FilePath + '" AGREETOLICENSE=yes INSTALLFOLDER="' + InstallFolderPath + '"' , '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
if ResultCode = ERROR_SUCCESS_REBOOT_REQUIRED then
RebootRequired := true
else if ResultCode <> ERROR_SUCCESS then
RaiseException(CustomMessage('MsiInstallationError'));
end;
为此,您需要使用Exec函数。
该文档有一个示例:
这里需要注意变量
ResultCode,它是通过引用传递给函数的,函数执行完毕后会写入完成代码。标志
ewWaitUntilTerminated强制等待被调用命令的完成。以下是安装 MSI 软件包的示例: