Files in use extension

From ISXKB

Jump to: navigation, search
(updated for IssProc v1.0.2)

Contents

Introduction

Files-In-Use functionality is among the countless services that Windows Installer exposes for setup authors to leverage for their application installation/maintenance. This functionality lets setup authors display the processes that hold on to files that would be updated by this install. The user would want to shut those processes before continuing with the installation to ensure that the install wouldn’t require a reboot.

Solution

You can do the same thing with Inno Setup avoiding unnecessary reboots when installing your application exe files / plugin / shell extension / ocx etc with [Files-In-Use Extension for Inno Setup]

Image:Issproc102.gif

Features:

  • multi-language support (you can add or modify the language file)
  • multiple file search (a semicolon list with exe/dll/ocx names and path can be used)
  • wildcard file match ( * = matches any characters, zero or more times ; ? = matches any character, one time )
  • exact folder match (detect if your file is in use only from a specified folder )
  • applications exe names will be listed not just their description
  • both 32 and 64 bit applications detection (Vista & XP x64 )
  • user friendly: applications are displayed along with their icon
  • possibility to end the detected process forcedly (right click on process for more options)
  • small size (it will add ~50KB to your setup)
  • easy to use and 100% free


Implementation

How do I get it to work with Inno?

1. Download Files-In-Use Extension for Inno Setup (IssProc.dll and Inno script demo included)

The code

2. Add the extension (IssProc.dll) to the [Files] section in your script:

[Files]
;------ add Files In Use Extension
Source: IssProc.dll; DestDir: {tmp}; Flags: dontcopy
;------ add Files In Use Extension extra language file (you don t need to add this file if you are using english only)
Source: IssProcLanguage.ini; DestDir: {tmp}; Flags: dontcopy
;------ Copy IssProc.dll in your app folder if you want to use it on unistall
Source: IssProc.dll; DestDir: {app}
Source: IssProcLanguage.ini; DestDir: {app}
;------

3. Add the code below to your script's [Code] section (you can modify it as you like):

[Code]
// IssFindModule called on install
function IssFindModule(hWnd: Integer; Modulename: PChar; Language: PChar; Silent: Boolean; CanIgnore: Boolean ): Integer;
external 'IssFindModule@files:IssProc.dll stdcall setuponly';
// IssFindModule called on uninstall
function IssFindModuleU(hWnd: Integer; Modulename: PChar; Language: PChar; Silent: Boolean; CanIgnore: Boolean ): Integer;
external 'IssFindModule@{app}\IssProc.dll stdcall uninstallonly';
//********************************************************************************************************************************************
// IssFindModule function returns: 0 if no module found; 1 if cancel pressed; 2 if ignore pressed; -1 if an error occured
//
//  hWnd		= main wizard window handle.
//
//  Modulename  = module name(s) to check. You can use a full path to a DLL/EXE/OCX or wildcard file name/path. Separate multiple modules with semicolon.
//				 Example1 : Modulename='*mymodule.dll';	 -  will search in any path for mymodule.dll
//				 Example2 : Modulename=ExpandConstant('{app}\mymodule.dll');	 -  will search for mymodule.dll only in {app} folder (the application directory)
//				 Example3 : Modulename=ExpandConstant('{app}\mymodule.dll;*myApp.exe');   - just like Example2 + search for myApp.exe regardless of his path.
//
//  Language	= files in use language dialog. Set this value to empty '' and default english will be used
//				( see and include IssProcLanguage.ini if you need custom text or other language)
//
//  Silent	  = silent mode : set this var to true if you don't want to display the files in use dialog.
//				When Silent is true IssFindModule will return 1 if it founds the Modulename or 0 if nothing found
//
//  CanIgnore   = set this var to false to Disable the Ignore button forcing the user to close those applications before continuing
//				set this var to true to Enable the Ignore button allowing the user to continue without closing those applications
//******************************************************************************************************************************************
function NextButtonClick(CurPage: Integer): Boolean;
var
  hWnd: Integer;
  sModuleName: String;
  nCode: Integer;  {IssFindModule returns: 0 if no module found; 1 if cancel pressed; 2 if ignore pressed; -1 if an error occured }
begin
  Result := true;
 if CurPage = wpReady then
   begin
	  Result := false;
	  ExtractTemporaryFile('IssProcLanguage.ini');						  { extract extra language file - you don't need to add this line if you are using english only }
	  hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));					 { get main wizard handle }
	  sModuleName :=ExpandConstant('{app}\Myprog.exe');					 { searched modules. Tip: separate multiple modules with semicolon Ex: '*mymodule.dll;*mymodule2.dll;*mymodule3.dll'}
	 nCode:=IssFindModule(hWnd,sModuleName,'en',false,true);				{ search for module and display files-in-use window if found  }
	 //sModuleName:=IntToStr(nCode);
	// MsgBox ( sModuleName, mbConfirmation, MB_YESNO or MB_DEFBUTTON2);
	 if nCode=1 then  begin												 { cancel pressed or files-in-use window closed }
		  PostMessage (WizardForm.Handle, $0010, 0, 0);					 { quit setup, $0010=WM_CLOSE }
	 end else if (nCode=0) or (nCode=2) then begin						  { no module found or ignored pressed}
		  Result := true;												   { continue setup  }
	 end;
  end;
end;
function InitializeUninstall(): Boolean;
var
  sModuleName: String;
  nCode: Integer;  {IssFindModule returns: 0 if no module found; 1 if cancel pressed; 2 if ignore pressed; -1 if an error occured }
begin
	Result := false;
	  sModuleName := ExpandConstant('*Myprog.exe;');	{ searched module. Tip: separate multiple modules with semicolon Ex: '*mymodule.dll;*mymodule2.dll;*myapp.exe'}
	 nCode:=IssFindModuleU(0,sModuleName,'enu',false,false); { search for module and display files-in-use window if found  }
	 if (nCode=0) or (nCode=2) then begin					{ no module found or ignored pressed}
		  Result := true;									{ continue setup  }
	 end;
	// Unload the extension, otherwise it will not be deleted by the uninstaller
	UnloadDLL(ExpandConstant('{app}\IssProc.dll'));
end;

4. Set sModuleName from the above code with your own modules names (separate multiple modules with semicolon)

5. Compile and test your setup. Before Inno will begin install operation The File In Use Extension will check if your modules (DLL’s/exe’s/ocx’s names) are in use and it will popup with a window asking the user to close those applications. The user can choose to Ignore this and continue with setup rebooting at the end, or he can close those applications and click on Retry.

See also

External links

Personal tools
Ads: