diff --git a/win_setup.iss b/win_setup.iss index 5a954c9..824459c 100644 --- a/win_setup.iss +++ b/win_setup.iss @@ -40,9 +40,11 @@ BeveledLabel= {#AppVersion}.{#SetupVersion} [CustomMessages] fr.AppName=Modèles pour Revues.org fr.WordNotFound=Attention! La détection de Microsoft Word a échoué. Souhaitez-vous quand même poursuivre l'installation ? +fr.PleaseCloseWord=Microsoft Word est actuellement en cours d'utilisation. Veuillez quitter tous les processus de Word en cours d'exécution puis cliquer sur OK. en.AppName=Revues.org Templates en.WordNotFound=Warning! Detection of Microsoft Word has failed. Do you want to force installation? +en.PleaseCloseWord=Microsoft Word is currently running. Please exit all Microsoft Word processes before continuing. [Languages] Name: "fr"; MessagesFile: "compiler:Languages\French.isl" @@ -58,6 +60,9 @@ Source: "src\img\revuesorg.ico"; DestDir: "{app}"; Flags: ignoreversion overwrit ; Anciens fichiers à supprimer Type: files; Name: "{userappdata}\Microsoft\Templates\revuesorg_complet.dot" +[UninstallRun] +Filename: "taskkill"; Parameters: "/im ""winword.exe"""; Flags: runhidden + [Code] var Msg: String; @@ -67,9 +72,30 @@ begin Result := DirExists(ExpandConstant('{userappdata}\Microsoft\Templates')) and DirExists(ExpandConstant('{userappdata}\Microsoft\Word\STARTUP')); end; +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; + function InitializeSetup(): Boolean; +var + AskCloseWord: Boolean; + begin Log('InitializeSetup called'); + + // Detection des templates Result := True; if WordExists() = False then begin @@ -80,4 +106,19 @@ begin Result := True; end; end; + + // Ne pas installer si process winword en cours + if Result then + begin + AskCloseWord := True; + while (IsAppRunning('winword.exe') and AskCloseWord) do + begin + Msg := CustomMessage('PleaseCloseWord'); + if MsgBox(Msg, mbConfirmation, MB_OKCANCEL) = IDCANCEL then + begin + AskCloseWord := False; + Result := False; + end; + end; + end; end;