Inno Setup Pascal Script pour rechercher le processus en cours

J’essaie actuellement de faire une validation au moment de la désinstallation. Dans une fonction de script Pascal, dans Inno Setup, je souhaite rechercher un processus spécifique, avec un caractère générique si possible. Ensuite, parcourez tous les résultats de la recherche, obtenez le nom de l’image et le nom du chemin de l’image afin de vérifier si le programme sur le point d’être désinstallé est identique à celui qui s’exécute.

Y-a-t-il un moyen de faire ça?

C’est une tâche exemplaire pour WMI et son langage WQL. Obtenir la liste des processus en cours d’exécution via WMI est encore plus fiable que l’API Windows. L’exemple ci-dessous montre comment interroger la classe Win32_Process avec l’opérateur LIKE :

 [Setup] AppName=My Program AppVersion=1.5 DefaultDirName={pf}\My Program DefaultGroupName=My Program [Code] type TProcessEntry = record PID: DWORD; Name: ssortingng; Description: ssortingng; ExecutablePath: ssortingng; end; TProcessEntryList = array of TProcessEntry; function GetProcessList(const Filter: ssortingng; out List: TProcessEntryList): Integer; var I: Integer; WQLQuery: ssortingng; WbemLocator: Variant; WbemServices: Variant; WbemObject: Variant; WbemObjectSet: Variant; begin Result := 0; WbemLocator := CreateOleObject('WbemScripting.SWbemLocator'); WbemServices := WbemLocator.ConnectServer('localhost', 'root\CIMV2'); WQLQuery := 'SELECT ' + 'ProcessId, ' + 'Name, ' + 'Description, ' + 'ExecutablePath ' + 'FROM Win32_Process ' + 'WHERE ' + 'Name LIKE "%'+ Filter +'%"'; WbemObjectSet := WbemServices.ExecQuery(WQLQuery); if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then begin Result := WbemObjectSet.Count; SetArrayLength(List, WbemObjectSet.Count); for I := 0 to WbemObjectSet.Count - 1 do begin WbemObject := WbemObjectSet.ItemIndex(I); if not VarIsNull(WbemObject) then begin List[I].PID := WbemObject.ProcessId; List[I].Name := WbemObject.Name; List[I].Description := WbemObject.Description; List[I].ExecutablePath := WbemObject.ExecutablePath; end; end; end; end; procedure InitializeWizard; var S: ssortingng; I: Integer; Filter: ssortingng; ProcessList: TProcessEntryList; begin MsgBox('Now we try to list processes containing "sv" in their names...', mbInformation, MB_OK); Filter := 'sv'; if GetProcessList(Filter, ProcessList) > 0 then for I := 0 to High(ProcessList) do begin S := Format( 'PID: %d' + #13#10 + 'Name: %s' + #13#10 + 'Description: %s' + #13#10 + 'ExecutablePath: %s', [ ProcessList[I].PID, ProcessList[I].Name, ProcessList[I].Description, ProcessList[I].ExecutablePath]); MsgBox(S, mbInformation, MB_OK); end; end;