inno 安装 检测进程

[Code]

var

ErrorCode: Integer;

IsRunning: Integer;

// 安装时判断客户端是否正在运行

function InitializeSetup(): Boolean;

begin

Result :=true; //安装程序继续

IsRunning:=FindWindowByWindowName('E家人客户端');

while IsRunning<>0 do

begin

if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then

begin

Result :=false; //安装程序退出

IsRunning :=0;

end else begin

Result :=true; //安装程序继续

IsRunning:=FindWindowByWindowName('E家人客户端');

end;

end;

end;

// 卸载时判断客户端是否正在运行

function InitializeUninstall(): Boolean;

begin

Result :=true; //安装程序继续

IsRunning:=FindWindowByWindowName('E家人客户端');

while IsRunning<>0 do

begin

if Msgbox('安装程序检测到客户端正在运行。' #13#13 '您必须先关闭它然后单击“是”继续安装,或按“否”退出!', mbConfirmation, MB_YESNO) = idNO then

begin

Result :=false; //安装程序退出

IsRunning :=0;

end else begin

Result :=true; //安装程序继续

IsRunning:=FindWindowByWindowName('E家人客户端');

end;

end;

end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);

begin

case CurUninstallStep of

usUninstall:

begin // 开始卸载

end;

usPostUninstall:

begin // 卸载完成

// MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall just finished.', mbInformation, MB_OK);

// ...insert code to perform post-uninstall tasks here...

ShellExec('open', 'http://domain', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);

end;

end;

end;



1、32位程序的PSVince.dll插件方法。

[Setup]
AppName=PSVince
AppVerName=PSVince 1.0
DisableProgramGroupPage=true
DisableStartupPrompt=true
OutputDir=.
OutputBaseFilename=testpsvince
Uninstallable=false
DisableDirPage=true
DefaultDirName={pf}\PSVince

[Files]
Source: psvince.dll; Flags: dontcopy

[Code]
function IsModuleLoaded(modulename: AnsiString ):   Boolean;
external 'IsModuleLoaded@files:psvince.dll stdcall';

function InitializeSetup(): Boolean;
begin
   if(IsModuleLoaded( 'notepad.exe' )) then
      begin
         MsgBox('Running', mbInformation, MB_OK);
         Result := false;
      end
   else
      begin
         MsgBox('Not running', mbInformation, MB_OK);
         Result := true;
      end
end;

2、 PSVince控件在64位系统(Windows 7/Server 2008/Server 2012)下无法检测到进程,使用下面的函数可以解决。
function IsAppRunning(const FileName : string): Boolean;
var
      FSWbemLocator: Variant;
      FWMIService    : Variant;
      FWbemObjectSet: Variant;
begin
      Result := false;
      FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
      FWMIService := FSWbemLocator.ConnectServer('', 'root\CIMV2', '', '');
      FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
      Result := (FWbemObjectSet.Count > 0);
      FWbemObjectSet := Unassigned;
      FWMIService := Unassigned;
      FSWbemLocator := Unassigned;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值