如何运用inno在安装和卸载时提示用户结束进程?

我尝试着写了一段,但是卸载段存在问题,请指点!

CODE

[Files]
Source: ISTask.dll; DestDir: {app}; Flags: ignoreversion

[Code]
function RunTask(FileName: string; bFullpath: Boolean): Boolean;
external 'RunTask@files:ISTask.dll stdcall delayload';

function KillTask(ExeFileName: string): Integer;
external 'KillTask@files:ISTask.dll stdcall delayload';

function InitializeSetup(): Boolean;
begin
Result:= true;
  if RunTask('MyProg.exe', false) then
  begin
    if
MsgBox('安装程序检测到 MyProg.exe 正在运行!'#13''#13'单击“是”按钮关闭 LockOn
程序;'#13''#13'单击“否”按钮进行强制安装!', mbConfirmation, MB_YESNO) = IDYES then
      KillTask('MyProg.exe');
  end
end;

function InitializeUninstall(): Boolean;
begin
Result:= true;
  if RunTask('MyProg.exe', false) then
  begin
    if
MsgBox('安装程序检测到 MyProg.exe 正在运行!'#13''#13'单击“是”按钮关闭 LockOn
程序;'#13''#13'单击“否”按钮进行强制安装!', mbConfirmation, MB_YESNO) = IDYES then
      KillTask('MyProg.exe');
  end
end;

======================================================

======================================================

======================================================

用上面的代码,在卸载时判断进程的dll已经没有了,所以不能调用它的函数。其实安装和卸载时调用的dll是不同的。

这样修改代码应该可以:

CODE

[Files]
Source: ISTask.dll; DestDir: {app}; Flags: ignoreversion

[Code]
function RunTask1(FileName: string; bFullpath: Boolean): Boolean;
external 'RunTask@files:ISTask.dll stdcall delayload';

function KillTask1(ExeFileName: string): Integer;
external 'KillTask@files:ISTask.dll stdcall delayload';

function RunTask(FileName: string; bFullpath: Boolean): Boolean;
external 'RunTask@{app}\ISTask.dll stdcall uninstallonly';

function KillTask(ExeFileName: string): Integer;
external 'KillTask@{app}\ISTask.dll stdcall uninstallonly';

function InitializeSetup(): Boolean;
begin
Result:= true;
  if RunTask1('MyProg.exe', false) then
  begin
    if
MsgBox('安装程序检测到 MyProg.exe 正在运行!'#13''#13'单击“是”按钮关闭 LockOn
程序;'#13''#13'单击“否”按钮进行强制安装!', mbConfirmation, MB_YESNO) = IDYES then
      KillTask1('MyProg.exe');
  end
end;

function InitializeUninstall(): Boolean;
begin
Result:= true;
  if RunTask('MyProg.exe', false) then
  begin
    if
MsgBox('安装程序检测到 MyProg.exe 正在运行!'#13''#13'单击“是”按钮关闭 LockOn
程序;'#13''#13'单击“否”按钮进行强制安装!', mbConfirmation, MB_YESNO) = IDYES then
      KillTask('MyProg.exe');
    UnloadDll(ExpandConstant('{app}\ISTask.dll'));
  end
end;

上一篇:(1)Maven快速入门_1maven安装


下一篇:GIS 地理坐标分类