Inno Setup检查运行过程

Had*_*ari 5 inno-setup

我有一个Inno安装项目,我想在卸载之前检查应用程序是否实际运行.我尝试了很多方法但是在Windows 7中运行时它都无声地失败.例如,无论记事本是否正在运行,以下notepad.exe使用psvince.dllalways 检查进程的脚本都会返回false.

psvince.dll在C#应用程序中使用它来检查,如果它在Windows 7下工作,它的工作没有任何问题.所以我最好的猜测是安装程序无法在启用UAC的情况下正常运行.

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

function InitializeSetup(): Boolean;
begin
   if(Not IsModuleLoaded('ePub.exe')) then
   begin
       MsgBox('Application is not running.', mbInformation, MB_OK);
       Result := true;
   end
   else
   begin
       MsgBox('Application is already running. Close it before uninstalling.', mbInformation, MB_OK);
       Result := false;
   end
end;
Run Code Online (Sandbox Code Playgroud)

mla*_*aan 7

您使用的是Unicode Inno Setup吗?如果你是,那应该说

function IsModuleLoaded(modulename: AnsiString): Boolean;
Run Code Online (Sandbox Code Playgroud)

因为psvince.dll不是Unicode dll.

此示例还检查epub.exe,而不是notepad.exe.


sas*_*alm 5

Inno Setup 实际上有一个 AppMutex 指令,该指令在帮助中进行了记录。实现它需要 2 行代码。

在 iss 文件的 [Setup] 部分中添加:

AppMutex=MyProgramsMutexName
Run Code Online (Sandbox Code Playgroud)

然后在应用程序启动期间添加以下代码行:

CreateMutex(NULL, FALSE, "MyProgramsMutexName");
Run Code Online (Sandbox Code Playgroud)


ari*_*wez 5

您也可以尝试使用WMIService:

procedure FindApp(const AppName: String);
var
  WMIService: Variant;
  WbemLocator: Variant;
  WbemObjectSet: Variant;
begin
  WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  WMIService := WbemLocator.ConnectServer('localhost', 'root\CIMV2');
  WbemObjectSet :=
    WMIService.ExecQuery('SELECT * FROM Win32_Process Where Name="' + AppName + '"');
  if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
  begin
    Log(AppName + ' is up and running');
  end;
end;
Run Code Online (Sandbox Code Playgroud)