gpt4 book ai didi

inno-setup - Inno Setup Exec() 函数等待有限的时间

转载 作者:行者123 更新时间:2023-12-04 18:12:23 28 4
gpt4 key购买 nike

在我的 Inno Setup 脚本中,我正在执行 3rd 方可执行文件。我正在使用 Exec()功能如下:

Exec(ExpandConstant('{app}\SomeExe.exe'), '', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);

通过提及 ewWaitUntilTerminated它等到 SomeExe.exe不退出。我只想等待 10 秒。

有什么解决办法吗?

最佳答案

假设您要执行外部应用程序,等待其终止指定的时间,如果它本身没有终止,则从安装程序中杀死它,请尝试以下代码。对于这里使用的神奇常量,在 WaitForSingleObject 中使用了3000作为参数。函数是设置等待进程终止的时间(以毫秒为单位)。如果它在那个时候没有自己终止,它会被 TerminateProcess 杀死。函数,其中 666 值是进程退出代码(在这种情况下非常邪恶:-)

[Code]
#IFDEF UNICODE
#DEFINE AW "W"
#ELSE
#DEFINE AW "A"
#ENDIF

const
WAIT_TIMEOUT = $00000102;
SEE_MASK_NOCLOSEPROCESS = $00000040;

type
TShellExecuteInfo = record
cbSize: DWORD;
fMask: Cardinal;
Wnd: HWND;
lpVerb: string;
lpFile: string;
lpParameters: string;
lpDirectory: string;
nShow: Integer;
hInstApp: THandle;
lpIDList: DWORD;
lpClass: string;
hkeyClass: THandle;
dwHotKey: DWORD;
hMonitor: THandle;
hProcess: THandle;
end;

function ShellExecuteEx(var lpExecInfo: TShellExecuteInfo): BOOL;
external 'ShellExecuteEx{#AW}@shell32.dll stdcall';
function WaitForSingleObject(hHandle: THandle; dwMilliseconds: DWORD): DWORD;
external 'WaitForSingleObject@kernel32.dll stdcall';
function TerminateProcess(hProcess: THandle; uExitCode: UINT): BOOL;
external 'TerminateProcess@kernel32.dll stdcall';

function NextButtonClick(CurPageID: Integer): Boolean;
var
ExecInfo: TShellExecuteInfo;
begin
Result := True;

if CurPageID = wpWelcome then
begin
ExecInfo.cbSize := SizeOf(ExecInfo);
ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ExecInfo.Wnd := 0;
ExecInfo.lpFile := 'calc.exe';
ExecInfo.nShow := SW_HIDE;

if ShellExecuteEx(ExecInfo) then
begin
if WaitForSingleObject(ExecInfo.hProcess, 3000) = WAIT_TIMEOUT then
begin
TerminateProcess(ExecInfo.hProcess, 666);
MsgBox('You just killed a little kitty!', mbError, MB_OK);
end
else
MsgBox('The process was terminated in time!', mbInformation, MB_OK);
end;
end;
end;

我在 Windows 7 上使用 Inno Setup 5.4.3 Unicode 和 ANSI 版本测试的代码(感谢 kobik 的想法,即使用来自 this post 的 Windows API 函数声明的条件定义)

关于inno-setup - Inno Setup Exec() 函数等待有限的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10892452/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com