Inno- Check if a process is running and show a message box if its running and... do some other things

1.7k Views Asked by At

Here is my Inno Setup script:

;InnoSetupVersion=5.5.0
;Script made in Inno Setup Ultra v5.5.1.ee2

[Setup]
AppName=Adobe Flash Player 15 + Shockwave Player 12 + Adobe Air 15 - AiO
AppVersion=15.12.15
AppPublisher=Adobe Systems, Inc.
AppPublisherURL=www.adobe.com
OutputBaseFilename=AdobeRuntimes_AiO_15.12.15_niTe.RiDeR
Compression=lzma2/ultra64
Uninstallable=no
DisableProgramGroupPage=yes
WizardImageFile=embedded\WizardImage.bmp
LicenseFile=embedded\LicenseAgreement.rtf
SolidCompression=yes
InternalCompressLevel=ultra
SetupIconFile=embedded\SetupIcon.ico
WizardSmallImageFile=embedded\WizardSmallImage.bmp
VersionInfoVersion=15.12.15
VersionInfoCompany=Adobe Systems Incorporated
VersionInfoDescription=Adobe Runtimes AiO (Adobe Shockwave Player v12.1.4.154 + Flash Player v15.0.0.223 + Adobe AIR) RePacked Setup
VersionInfoProductName=Adobe Runtimes AiO
VersionInfoProductVersion=15.12.15
VersionInfoProductTextVersion=12.12.15
CreateAppDir=False

[Files]
Source: "{app}\install_flash_player_15_active_x.exe"; DestDir: "{tmp}"; Components: flashactivex; MinVersion: 0.0,5.01; Flags: deleteafterinstall
Source: "{app}\install_flash_player_15_plugin.exe"; DestDir: "{tmp}"; Components: flashplugin; MinVersion: 0.0,5.01; Flags: deleteafterinstall
Source: "{app}\sw_lic_full_installer.msi"; DestDir: "{tmp}"; Components: shockwave; MinVersion: 0.0,5.01; Flags: deleteafterinstall
Source: "{app}\AdobeAIRInstaller.exe"; DestDir: "{tmp}"; Components: air; MinVersion: 0.0,5.01; Flags: deleteafterinstall 
Source: "embedded\ISWin7.dll"; DestDir: "{tmp}"; Flags: dontcopy nocompression

[Run]
Filename: "{tmp}\install_flash_player_15_active_x.exe"; Parameters: "-install"; StatusMsg: "Installing Flash Player 15 ActiveX; This can take a few minutes & the installer will freeze for a few seconds, so please wait..."; Components: flashactivex; MinVersion: 0.0,5.01;
Filename: "{tmp}\install_flash_player_15_plugin.exe"; Parameters: "-install"; StatusMsg: "Installing Flash Player 15 Plugin; this can take few minutes & the installer will freeze for a few seconds, so please wait..."; Components: flashplugin; MinVersion: 0.0,5.01;
Filename: "{tmp}\sw_lic_full_installer.exe"; Parameters: "/qb"; StatusMsg: "Installing Shockwave Player 12; This could take a few minutes & the installer will freeze for a few seconds, so please wait..."; Components: shockwave; MinVersion: 0.0,5.01;
Filename: "{tmp}\AdobeAIRInstaller.exe"; Parameters: "-silent"; StatusMsg: "Installing Adobe AIR 15; this may take a few minutes & the installer will freeze for a few seconds, so please wait..."; Components: air; MinVersion: 0.0,5.01;

[Components]
Name: "flashplugin"; Description: "Adobe Flash Player v15.0.0.223 Plugin"; Types: "compact full"; MinVersion: 0.0,5.01; ExtraDiskSpaceRequired: 10485760
Name: "flashactivex"; Description: "Adobe Flash Player v15.0.0.223 ActiveX"; Types: "compact full"; MinVersion: 0.0,5.01; ExtraDiskSpaceRequired: 10485760
Name: "shockwave"; Description: "Adobe Shockwave Player v12.1.4.154"; Types: "compact full"; MinVersion: 0.0,5.01; ExtraDiskSpaceRequired: 10485760
Name: "air"; Description: "Adobe AIR v15.0.0.356"; Types: "full"; MinVersion: 0.0,5.01; ExtraDiskSpaceRequired: 10485760

[Messages]
SelectComponentsLabel2=Select the runtimes you want to install; clear the runtimes you do not want to install. Click Next when you are ready to continue.
WizardSelectComponents=Select Runtimes
SelectComponentsDesc=Which runtimes should be installed?

[Code]
{ RedesignWizardFormBegin } // Don't remove this line!
// Don't modify this section. It is generated automatically.
var
  ISCustomPage2: TWizardPage;
  ISCustomPage3: TWizardPage;
  ISCustomPage1: TWizardPage;
  ISCustomPage4: TWizardPage;
  Label1: TLabel;
  Label2: TLabel;
  Label3: TLabel;
  Label4: TLabel;
  Label5: TLabel;
  Label6: TLabel;
  Label7: TLabel;

procedure RedesignWizardForm;
begin
  { Creates custom wizard page }
  ISCustomPage4 := CreateCustomPage(wpWelcome, 'Description', 'A Description of the Runtimes (Components)');

  with WizardForm do
  begin
    AutoScroll := False;
    ClientHeight := ScaleY(363);
    ClientWidth := ScaleX(490);
    Caption := 'Setup - Adobe Runtimes AiO RePack';
  end;

  with WizardForm.CancelButton do
  begin
    Left := ScaleX(404);
  end;

  with WizardForm.NextButton do
  begin
    Left := ScaleX(319);
  end;

  with WizardForm.BackButton do
  begin
    Left := ScaleX(244);
  end;

  with WizardForm.WizardBitmapImage do
  begin
    Width := ScaleX(180);
  end;

  with WizardForm.WelcomeLabel2 do
  begin
    Caption := 'This will install Adobe Flash Player 15 + Shockwave Player 12 + Adobe Air 15 - AiO on your computer.' + #13#10 +
         '' + #13#10 +
         'It is recommended that you close all other applications before continuing.' + #13#10 +
         'You can choose which runtimes to install.' + #13#10 +
         '' + #13#10 +
         'Click Next to continue, or Cancel to exit Setup.';
    Left := ScaleX(184);
    Top := ScaleY(96);
    Width := ScaleX(293);
    Height := ScaleY(212);
  end;

  with WizardForm.WelcomeLabel1 do
  begin
    Caption := 'Welcome to the Adobe Runtimes AIO Setup Wizard by -=niTe_RiDeR_Pro=-';
    Left := ScaleX(184);
    Width := ScaleX(307);
    Height := ScaleY(78);
  end;

  with WizardForm.ComponentsList do
  begin
    Top := ScaleY(69);
  end;

  { Label7 }
  Label7 := TLabel.Create(WizardForm);
  with Label7 do
  begin
    Name := 'Label7';
    Parent := WizardForm;
    Caption := 'RePack by niTe_RiDeR_Pro';
    Font.Color := clWindowText;
    Font.Height := -11;
    Font.Name := 'Tahoma';
    Font.Style := [fsItalic];
    ParentFont := False;
    Left := ScaleX(14);
    Top := ScaleY(331);
    Width := ScaleX(130);
    Height := ScaleY(13);
  end;

  { ISCustomPage4 }
  with ISCustomPage4.Surface do
  begin
    Color := clBtnFace;
  end;

  { Label1 }
  Label1 := TLabel.Create(WizardForm);
  with Label1 do
  begin
    Parent := ISCustomPage4.Surface;
    Caption := 'Adobe Flash Player:';
    Font.Color := clWindowText;
    Font.Height := -11;
    Font.Name := 'Tahoma';
    Font.Style := [fsBold];
    ParentFont := False;
    Left := ScaleX(8);
    Top := ScaleY(8);
    Width := ScaleX(110);
    Height := ScaleY(13);
  end;

  { Label2 }
  Label2 := TLabel.Create(WizardForm);
  with Label2 do
  begin
    Parent := ISCustomPage4.Surface;
    AutoSize := False;
    Caption := 'Adobe Flash Player is the standard for delivering high-impact, rich Web content. ' + #13#10 +
         'Designs, animation, and application user interfaces are deployed immediately across' + #13#10 +
         'attracting and engaging users with a rich Web experience.';
    Left := ScaleX(8);
    Top := ScaleY(24);
    Width := ScaleX(407);
    Height := ScaleY(61);
  end;

  { Label3 }
  Label3 := TLabel.Create(WizardForm);
  with Label3 do
  begin
    Parent := ISCustomPage4.Surface;
    Caption := 'Adobe Shockwave Player:';
    Font.Color := clWindowText;
    Font.Height := -11;
    Font.Name := 'Tahoma';
    Font.Style := [fsBold];
    ParentFont := False;
    Left := ScaleX(8);
    Top := ScaleY(80);
    Width := ScaleX(145);
    Height := ScaleY(13);
  end;

  { Label4 }
  Label4 := TLabel.Create(WizardForm);
  with Label4 do
  begin
    Parent := ISCustomPage4.Surface;
    Caption := 'Shockwave Player is the web standard for powerful multimedia playback. The ' + #13#10 +
         'Shockwave Player allows you to view interactive web content like games,' + #13#10 +
         ' business presentations, entertainment, and advertisements from your web browser. ';
    Left := ScaleX(8);
    Top := ScaleY(96);
    Width := ScaleX(412);
    Height := ScaleY(39);
  end;

  { Label5 }
  Label5 := TLabel.Create(WizardForm);
  with Label5 do
  begin
    Parent := ISCustomPage4.Surface;
    Caption := 'Adobe AIR:';
    Font.Color := clWindowText;
    Font.Height := -11;
    Font.Name := 'Tahoma';
    Font.Style := [fsBold];
    ParentFont := False;
    Left := ScaleX(8);
    Top := ScaleY(152);
    Width := ScaleX(63);
    Height := ScaleY(13);
  end;

  { Label6 }
  Label6 := TLabel.Create(WizardForm);
  with Label6 do
  begin
    Parent := ISCustomPage4.Surface;
    Caption := 'Adobe AIR is a cross-operating-system runtime that lets developers combine HTML, ' + #13#10 +
         'JavaScript, Adobe Flash® and Flex technologies, and ActionScript®; and also lets ' + #13#10 +
         'users to deploy rich Internet applications (RIAs) on a broad range of devices including ' + #13#10 +
         'desktop computers, netbooks, tablets, smartphones, and TVs. ';
    Left := ScaleX(8);
    Top := ScaleY(168);
    Width := ScaleX(415);
    Height := ScaleY(52);
  end;

  with WizardForm.MainPanel do
  begin
    Left := ScaleX(0);
    Top := ScaleY(0);
  end;

  with WizardForm.PageDescriptionLabel do
  begin
    Transparent := True;
    Left := ScaleX(24);
    Top := ScaleY(29);
  end;

  with WizardForm.PageNameLabel do
  begin
    AutoSize := True;
    Left := ScaleX(16);
    Top := ScaleY(8);
    Width := ScaleX(4);
  end;

{ ReservationBegin }
  // This part is for you. Add your specialized code here.

{ ReservationEnd }
end;
// Don't modify this section. It is generated automatically.
{ RedesignWizardFormEnd } // Don't remove this line!

procedure ISCustomPage1Activate(Sender: TWizardPage);
begin

end;

procedure iswin7_add_glass(Handle:HWND; Left, Top, Right, Bottom : Integer; GDIPLoadMode: boolean);
external 'iswin7_add_glass@files:iswin7.dll stdcall';
procedure iswin7_add_button(Handle:HWND);
external 'iswin7_add_button@files:iswin7.dll stdcall';
procedure iswin7_free;
external 'iswin7_free@files:iswin7.dll stdcall';

procedure InitializeWizard();
begin
  RedesignWizardForm;
    iswin7_add_button(WizardForm.BackButton.Handle);
    iswin7_add_button(WizardForm.NextButton.Handle);
    iswin7_add_button(WizardForm.CancelButton.Handle);
    iswin7_add_glass(WizardForm.Handle, 0, 0, 0, ScaleY(50), True);
end;

procedure DeinitializeSetup();
begin
    iswin7_free;
end;

At the time of installation, I want to do the following things if the user selects the component named 'flashplugin':

  • Check whether the process 'chrome.exe' & 'firefox.exe' is running, and show a message box if it is running. If google chrome is running, The message box should show 'Google Chrome is running. please close it or else the setup will close it automatically'; and if Firefox is running the messsage box should show 'Mozilla Firefox is running. please close it or else the setup will close it automatically'. If the user chooses OK and still any of the processes are open, the setup should kill it automatically.

What is the pascal coding for this ?

I would appreciate answers for this. thanks :)

1

There are 1 best solutions below

1
On

Possibly a duplicate, but this answer might be helpful for you. Thanks to Andrew Seaford:

[Code]
function IsAppRunning(const FileName: string): Boolean;
var
  FWMIService: Variant;
  FSWbemLocator: 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;
begin
  Result := not IsAppRunning('notepad.exe');
  if not Result then
  MsgBox('notepad.exe is running. Please close the application before running the installer ', mbError, MB_OK);
end;