方法有:
1.使用系统服务WinMgmts 系统信息
通过 "winmgmts:\\.\root\CIMV2" 遍历进程列表。
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;
注意:使用wim遍历进程必须开启wim服务
2.使用插件ISTask.dll,psvince.dll 发现有问题,没成功.
3.使用插innosetup自带的
function FindWindowByWindowName(const WindowName: String): HWND;函数
var appWnd: HWND;
begin
Result := false;
appWnd := FindWindowByWindowName('窗口名');
if (appWnd <> 0) then
begin
MsgBox('已有安装程序正在安装', mbConfirmation, MB_YESNO);
end;
end;