- May 18, 2019 Inno Setup Kill Process Before Install Average ratng: 5,5/10 5579 votes Inno setup is an installer framework made by jrsoftware.org. It is a super cool and FREE tool for making executable setup programs.
- End a process with Inno setup. 2018//02/22 - Dallas. These two functions will ctry to close the process gt4t.exe at installation and uninstallation. Execute command/batch file after install process is complete using Inno Setup. That do part of installation after user has finished install process and system has.
- As a software developer, I love Inno Setup! It is a wonderful, powerful, free software-deployment tool. I’ve tweaked my programs’ Inno Setup scripts to accomplish certain important, but tricky tasks. Most recently, I looked for a way to check if a program is running (and to close that program) when we’re about to install a new version.
- Download Inno Setup
- Inno Setup Service
- Kill Process Program
- Inno Setup Kill Process Before Install A Door
Inno Setup Unpacker takes the process further by extracting both the application files and the setup script of Inno Setup installers. (It won’t work with other types of setup files, but Inno is.
2020腾讯云10周年活动,优惠非常大!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1040
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1040
2020阿里云最低价产品入口,含代金券(新老用户有优惠),
地址:https://www.aliyun.com/minisite/goods
地址:https://www.aliyun.com/minisite/goods
up vote 14 down vote favorite 11 This should be simple, I need to stop any previous version of my program from running when the installer starts. Most people suggested making an exe which does this and calling it before Inno Setup starts. I created an exe using AutoIt which kills all processes of my program. The problem is I don't know how to get Inno Setup to call it before it installs anything. How do I call an executable before installing files? Alternatively, if I can just detect if a program is running and tell the user to close it, that would work too. installer inno-setup
|
this question edited Jun 21 '16 at 5:54 Martin Prikryl 48.3k 15 68 171 asked Aug 17 '10 at 23:46 Daisetsu 1,818 6 37 56
| 9 Answers|
this question edited Jun 21 '16 at 5:54 Martin Prikryl 48.3k 15 68 171 asked Aug 17 '10 at 23:46 Daisetsu 1,818 6 37 56
up vote 24 down vote ---Accepted---Accepted---Accepted---
If the application has a Mutex, you can add an AppMutex value in your Inno Setup installer and it will display a message telling the user to stop the program. You might be able to find the Mutex (if it's got one) by using SysInternals Process Explorer and selecting the program / process and looking at the Handles (CTRL-H) in the Lower Pane. Here's a link to the a KB article that mentions several methods: http://www.vincenzo.net/isxkb/index.php?title=Detect_if_an_application_is_running Alternatively, you might try this (UNTESTED) code in the InitializeSetup: [Setup]
;If the application has
Mutex, uncomment the line below, comment the InitializeSetup function out, and use the AppMutex.
;AppMutex=MyApplicationMutex
[Code]
const
WM_CLOSE = 16;
function InitializeSetup : Boolean;
var winHwnd: Longint;
retVal : Boolean;
strProg: string;
begin
Result := True;
try
//Either use FindWindowByClassName. ClassName can be found with Spy++ included with Visual C++.
strProg := 'Notepad';
winHwnd := FindWindowByClassName(strProg);
//Or FindWindowByWindowName.
If using by Name, the name must be exact and is case sensitive.
strProg := 'Untitled - Notepad';
winHwnd := FindWindowByWindowName(strProg);
Log('winHwnd: ' + IntToStr(winHwnd));
if winHwnd <> 0 then
Result := PostMessage(winHwnd,WM_CLOSE,0,0);
except
end;
end;
|
this answer edited Jun 21 '16 at 6:02 Martin Prikryl 48.3k 15 68 171 answered Aug 18 '10 at 1:34 mirtheil 5,661 17 21 Thanks Mirtheil, this is exactly what I needed. Everyone else provided reasonable answers but this turns out to be the perfect solution. – Daisetsu Aug 18 '10 at 18:35 does not work on Windows 7 – Mason Zhang Oct 19 '11 at 15:11 Actually, it didn't work on anything. Once the correct window name was used, it does work on Windows 7 and other OSes. I also added an alternative to FindWindowByWindowName which is FindWindowByClassName. FindWindowByClassName might be a better choice if your program's window name changes. – mirtheil Oct 19 '11 at 19:23 3 For Inno 5.5.0+ there's a new solution, as I explain in my late response to this question. – jachguate Nov 27 '12 at 11:25 According to the documentation, it is better to use the function PrepareToInstall instead of InitializeSetup to shutdown the application to update. – Zac Oct 27 '16 at 8:48 | show 1 more comment up vote 11 down vote In version 5.5.0 (Released on May 2012) Inno Setup added support for the Restart Manager API on Windows Vista and newer. Quote from MSDN linked documentation (emphasis mine): The primary reason software installation and updates require a system restart is that some of the files that are being updated are currently being used by a running application or service. Restart Manager enables all but the critical applications and services to be shut down and restarted. This frees the files that are in use and allows installation operations to complete. It can also eliminate or reduce the number of system restarts that are required to complete an installation or update. The good thing is not you don't need to write custom code in the installer or your application to ask the user to close it, or close it automatically. If you want your application to restart after the update is complete, you have to call the RegisterApplicationRestart function from your application first. The default values for the new directives closes all the .exe, .dll and .chm files contained within the [Files] section of the installer. The changes related to it are (from release notes): Added new [Setup] section directive: CloseApplications, which defaults to yes. If set to yes and Setup is not running silently, Setup will now pause on the Preparing to Install wizard page if it detects applications using files that need to be updated by the [Files] or [InstallDelete] section, showing the applications and asking the user if Setup should automatically close the applications and restart them after the installation has completed. If set to yes and Setup is running silently, Setup will always close and restart such applications, unless told not to via the command line (see below). Added new [Setup] section directive: CloseApplicationsFilter, which defaults to *.exe,*.dll,*.chm. Controls which files Setup will check for being in use. Setting this to *.* can provide better checking at the expense of speed. Added new [Setup] section directive: RestartApplications, which defaults to yes. Note: for Setup to be able to restart an application after the installation has completed, the application needs to be using the Windows RegisterApplicationRestart API function. Added new command line parameters supported by Setup: /NOCLOSEAPPLICATIONS and /NORESTARTAPPLICATIONS. These can be used to override the new CloseApplications and RestartApplications directives. Added new [Code] support function: RmSessionStarted. TWizardForm: Added new PreparingMemo property.
|
this answer edited Jun 21 '16 at 5:57 Martin Prikryl 48.3k 15 68 171 answered Nov 27 '12 at 11:23 jachguate 14.6k 1 35 73 2 great answer, thanks! – João Moreno Aug 7 '15 at 10:22
answer (and the follow up by jachguate) but it wouldn't kill my application. It looks like part of the reason was that my application window had no text associated with it but whatever is the real reason, I used shell command to kill it and that worked. In the [code] section, you want to add the following function. It is called just before setup files are copied. function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ErrorCode: Integer;
begin
ShellExec('open',
'taskkill.exe', '/f /im MyProg.exe',',SW_HIDE,ewNoWait,ErrorCode);
end;
|
this answer edited Sep 20 '16 at 20:59 answered Aug 5 '13 at 16:48 zar 3,033 3 30 68
|
this answer answered Aug 18 '10 at 0:13 Conor Boyd 803 5 13 That won't work as the program has been released for years and I will need to close down old versions too. – Daisetsu Aug 18 '10 at 0:27 | up vote 3 down vote Here's a link to an Inno Setup script that prompts a user to close the target program, if it detects that the program is running. After the user closes the program, they can click on a 'Retry' button to proceed with the installation: http://www.domador.net/extras/code-samples/inno-setup-close-a-program-before-reinstalling-it/ This script is based on a simpler script, found in the Inno Setup Extensions Knowledge Base: http://www.vincenzo.net/isxkb/index.php?title=Call_psvince.dll_on_install_and_uninstall
|
this answer answered May 18 '11 at 21:20 Andres Cabezas Ulate 51 2 | up vote 1 down vote If you are happy to write your own DLL, you can use the tool help API for TlHelp32.pas to determine what applications are running, and then get a window handle for them using EnumWindows, then send a WM_CLOSE to the window handle. It's a bit of a pain, but it should work: I have some utility wrapper classes I developed with a friend a while back. Can't remember if we based it on someone else's code. TWindows.ProcessISRunning and TWindows.StopProcess may help. interface
uses
Classes,
Windows,
SysUtils,
Contnrs,
Messages;
type
TProcess = class(TObject)
public
ID: Cardinal;
Name: string;
end;
TWindow = class(TObject)
private
FProcessID: Cardinal;
FProcessName: string;
FHandle: THandle;
FProcessHandle : THandle;
function GetProcessHandle: THandle;
function GetProcessID: Cardinal;
function GetProcessName: string;
public
property Handle : THandle read FHandle;
property ProcessName : string read GetProcessName;
property ProcessID : Cardinal read GetProcessID;
property ProcessHandle : THandle read GetProcessHandle;
end;
TWindowList = class(TObjectList)
private
function GetWindow(AIndex: Integer): TWindow;
protected
public
function Add(AWindow: TWindow): Integer; reintroduce;
property Window[AIndex: Integer]: TWindow read GetWindow; default;
end;
Mouse jiggler for mac. TProcessList = class(TObjectList)
protected
function GetProcess(AIndex: Integer): TProcess;
public
function Add(AProcess: TProcess): Integer; reintroduce;
property Process[AIndex: Integer]: TProcess read GetProcess; default;
end;
TWindows = class(TObject)
protected
public
class function GetHWNDFromProcessID(ProcessID: Cardinal; BuildList: Boolean = True): THandle;
class function GetProcessList: TProcessList;
class procedure KillProcess(ProcessName: string);
class procedure StopProcess(ProcessName: string);
class function ExeIsRunning(ExeName: string): Boolean;
class function ProcessIsRunning(PID: Cardinal): Boolean;
end;
implementation
uses
Forms,
Math,
PSAPI,
TlHelp32;
const
cRSPUNREGISTERSERVICE = 0;
cRSPSIMPLESERVICE = 1;
type
TProcessToHWND = class(TObject)
public
ProcessID: Cardinal;
HWND: Cardinal;
end;
function RegisterServiceProcess(dwProcessID, dwType: DWord): DWord; stdcall; external 'KERNEL32.DLL';
function GetDiskFreeSpaceEx(lpDirectoryName: PChar;
var lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes: TLargeInteger;
lpTotalNumberOfFreeBytes: PLargeInteger): Boolean; stdcall;external 'KERNEL32.DLL' name 'GetDiskFreeSpaceExA'
var
Coleman powermate cp5092016 air compressor parts manual. GProcessToHWNDList: TObjectList = nil;
function EnumerateWindowsProc(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;
var
proc: TProcessToHWND;
begin
if Assigned(GProcessToHWNDList) then
begin
proc := TProcessToHWND.Create;
proc.HWND := hwnd;
GetWindowThreadProcessID(hwnd, proc.ProcessID);
GProcessToHWNDList.Add(proc);
Result := True;
end
else
Result := False; // stop enumeration
end;
{ TWindows }
class function TWindows.ExeIsRunning(ExeName: string): Boolean;
var
processList: TProcessList;
i: Integer;
begin
Result := False;
processList := GetProcessList;
try
for i := 0 to processList.Count - 1 do
begin
if (UpperCase(ExeName) = UpperCase(processList[i].Name)) or
(UpperCase(ExeName) = UpperCase(ExtractFileName(processList[i].Name))) then
begin
Result := True;
Break;
Fsx fsuipc 4 09 movies. end;
end;
finally
processList.Free;
end;
class function TWindows.GetHWNDFromProcessID(
ProcessID: Cardinal; BuildList: Boolean): THandle;
var
i: Integer;
begin
Result := 0;
if BuildList or (not Assigned(GProcessToHWNDList)) then
begin
GProcessToHWNDList.Free;
GProcessToHWNDList := TObjectList.Create;
EnumWindows(@EnumerateWindowsProc, 0);
end;
for i := 0 to GProcessToHWNDList.Count - 1 do
begin
if TProcessToHWND(GProcessToHWNDList[i]).ProcessID = ProcessID then
begin
Result := TProcessToHWND(GProcessToHWNDList[i]).HWND;
Break;
end;
end;
end;
class function TWindows.GetProcessList: TProcessList;
var
handle: THandle;
pe: TProcessEntry32;
process: TProcess;
begin
Result := TProcessList.Create;
handle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe.dwSize := Sizeof(pe);
if Process32First(handle, pe) then
begin
while True do
begin
process := TProcess.Create;
process.Name := pe.szExeFile;
process.ID := pe.th32ProcessID;
Result.Add(process);
if not Process32Next(handle, pe) then
Break;
end;
end;
CloseHandle(handle);
end;
function EnumWindowsProc(Ahwnd : HWND;
// handle to parent window
ALParam : Integer) : BOOL;stdcall;
var
List : TWindowList;
Wnd : TWindow;
begin
Result := True;
List := TWindowList(ALParam);
Wnd := TWindow.Create;
List.Add(Wnd);
Wnd.FHandle := Ahwnd;
end;
class procedure TWindows.KillProcess(ProcessName: string);
var
handle: THandle;
pe: TProcessEntry32;
begin
// Warning: will kill all process with ProcessName
// NB won't work on NT 4 as Tool Help API is not supported on NT
handle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
try
pe.dwSize := Sizeof(pe);
if Process32First(handle, pe) then
begin
while True do begin
if (UpperCase(ExtractFileName(pe.szExeFile)) = UpperCase(ExtractFileName(ProcessName))) or
(UpperCase(pe.szExeFile) = UpperCase(ProcessName)) then
begin
if not TerminateProcess(OpenProcess(PROCESS_TERMINATE, False,
pe.th32ProcessID), 0) then
begin
raise Exception.Create('Unable to stop process ' + ProcessName + ': Error Code ' + IntToStr(GetLastError));
end;
end;
if not Process32Next(handle, pe) then
Break;
end;
end;
finally
CloseHandle(handle);
end;
end;
class function TWindows.ProcessIsRunning(PID: Cardinal): Boolean;
var
processList: TProcessList;
i: Integer;
begin
Result := False; How much is the millenium cabbage patch doll worth.
processList := GetProcessList;
try
for i := 0 to processList.Count - 1 do
begin
if processList[i].ID = PID then
begin
Result := True;
Break;
end;
end;
finally
processList.Free;
end;
end;
class procedure TWindows.StopProcess(ProcessName: string);
var
processList: TProcessList;
i: Integer;
hwnd: THandle;
begin
// Warning: will attempt to stop all process with ProcessName
Mount and blade warband armor. if not Assigned(GProcessToHWNDList) then
GProcessToHWNDList := TObjectList.Create
else
GProcessToHWNDList.Clear;
// get list of all current processes
processList := GetProcessList;
// enumerate windows only once to determine the window handle for the processes
if EnumWindows(@EnumerateWindowsProc, 0) then
begin
for i := 0 to processList.Count - 1 do
begin
if UpperCase(ExtractFileName(processList[i].Name)) = UpperCase(ExtractFileName(ProcessName)) then
begin
hwnd := GetHWNDFromProcessID(processList[i].ID, False);
SendMessage(hwnd, WM_CLOSE, 0, 0);
end;
end;
end;
end;
{ TProcessList }
function TProcessList.Add(AProcess: TProcess): Integer;
begin
Result := inherited Add(AProcess);
![Before Before](https://images.sftcdn.net/images/t_app-cover-l,f_auto/p/16accf72-96db-11e6-bf8a-00163ec9f5fa/3982751454/inno-setup-screenshot.jpg)
end;
function TProcessList.GetProcess(AIndex: Integer): TProcess;
begin
Result := TProcess(Items[AIndex]);
end;
{ TWindowList }
function TWindowList.Add(AWindow: TWindow): Integer;
begin
Result := inherited Add(AWindow);
end;
function TWindowList.GetWindow(AIndex: Integer): TWindow;
begin
Result := TWindow(Items[AIndex]);
end;
{ TWindow }
function TWindow.GetProcessHandle: THandle;
begin
if FProcessHandle = 0 then
FProcessHandle := OpenProcess(Windows.SYNCHRONIZE or Windows.PROCESS_TERMINATE,
True, FProcessID);
Result := FProcessHandle;
end;
function TWindow.GetProcessID: Cardinal;
var
Pid : Cardinal;
begin
Download Inno Setup
if FProcessID = 0 then
begin
Pid := 1;
GetWindowThreadProcessId(Handle, Pid);
FProcessID := Pid;
end;
Result := FProcessID;
end;
function TWindow.GetProcessName: string;
var
Buffer : packed array [1.1024] of char;
len : LongWord;
begin
FillChar(Buffer, SizeOf(Buffer), 0);
if FProcessName = ' then
begin
len := GetWindowModuleFileName(Handle, @Buffer[1], 1023);
FProcessName := Copy(Buffer, 1, Len);
end;
Result := FProcessName;
end;
end.
|
this answer answered Aug 18 '10 at 9:48 Gerry Coll 5,198 1 18 32 Failed to compile in InnoSetup, could anyone fix it? I never used pascal before. – Mason Zhang Oct 19 '11 at 14:34
var
ResultCode: Integer;
wmicommand: string;
begin
// before installing any file
if CurStep = ssInstall then
begin
wmicommand := ExpandConstant('PROCESS WHERE 'ExecutablePath like '{app}%%'' DELETE');
// WMIC 'like' expects escaped backslashes
StringChangeEx(wmicommand, ', ', True);
// you can/should add an 'if' around this and check the ResultCode
Exec('WMIC', wmicommand, ', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
end;
You can also do it in the InitializeSetup but if you do, keep in mind you don't have yet access to the {app} constant. My program doesn't ask for install path, but yours might.
|
this answer edited Mar 20 at 10:18 Community ♦ 1 1 answered Oct 6 '16 at 13:14 thomasb 3,040 2 36 67
| up vote 0 down vote InnoSetup allows you to attach Pascal scripts to various places in the build process. Try attaching a script that calls ShellExecute. (Which you may have to import to the script engine if it doesn't already have it.) |
this answer edited Mar 20 at 10:18 Community ♦ 1 1 answered Oct 6 '16 at 13:14 thomasb 3,040 2 36 67
|
this answer answered Aug 18 '10 at 0:12 Mason Wheeler 60k 30 198 369 The script engine has Exec() so that's not the problem. I can't figure out how to write the pascal code though to extract the bundled exe file and run it. – Daisetsu Aug 18 '10 at 0:27 | up vote 0 down vote Well, I think the easier way to perform this may be creating a DLL in Delphi that detects if your program is running and ask the user to close it, put that DLL in your setup and use the flag 'dontcopy' (check in http://www.jrsoftware.org/ishelp/ under Pascal Scripting Using DLLs for an example). Btw, next time use mutexes, Inno Setup also support that and is far more easier. EDIT: and for extracting a file (if you want to use that .exe you mention), just use ExtractTemporaryFile().
|
this answer answered Aug 18 '10 at 0:41 someone 896 1 5 8 |
up vote 14 down vote favorite 11 This should be simple, I need to stop any previous version of my program from running when the installer starts. Most people suggested making an ex
- 1android静默安装apk已经成功实现
- 2安装打包之VisualStuido
- 3[Oracle] UNIX与Windows 2000上Oracle的差异(III)
- 4使用Opencv 2.1/2.2 编译64位程序时,编译器内部错误 error c1001
- 5ORA-06553: PLS-213: package STANDARD not accessible
- 1微信公众号文章采集,并发布到WordPress
最新文章
- 1linux之universal usb installer安装ubuntu
- 2Windows程序安装包制作——Qt Installer Framework
- 3path too long installer unable to modify path 导致PCL配置失败记
- 4android sdk manager的extras中没有intel emulator accelerator(HAXM installer)
- 5Cloud Foundry 部署问题(2)buildpack时间过长
- 6VS2010程序打包操作(超详细的)
In this chapter, we will walk you through the process of creating an executable and then packaging it up into an installer. We will be using a really neat little user interface called GUI2Exe that was written by Andrea Gavana to create the executable. It is based on wxPython, so you will need to have that installed to use it. GUI2Exe supports py2exe, bbfreeze, cx_Freeze, PyInstaller and py2app. Then once we have the dist folder created, we will use Inno Setup to create our installer.
We will be using the following code once more:
Let’s get started!
Getting Started with GUI2Exe¶
To use GUI2Exe, you just have to go to its website (http://code.google.com/p/gui2exe/) and download a release. Then you unzip it and run the script that’s called GUI2Exe.py. The GUI2Exe project is based on wxPython, so make sure you have that installed as well. I ran mine successfully with wxPython 2.9. Here’s how you would call it:
If that executed successfully, you should see a screen similar to this one:
Now go to File -> New Project and give your project a name. In this case, I called the project wxForm. If you want to, you can add a fake Company Name, Copyright and give it a Program Name. Be sure to also browse for your main Python script (i.e. sampleApp.py). According to Andrea’s website, you should set Optimize to 2, Compressed to 2 and Bundled Files to 1. This seems to work most of the time, but I’ve had some screwy errors that seem to stem from setting the last one to 1. In fact, according to one of my contacts on the py2exe mailing list, the bundle option should be set to 3 to minimize errors. The nice thing about setting bundle to “1” is that you end up with just one file, but since I’m going to roll it up with Inno I’m going to go with option 3 to make sure my program works well.
Once you have everything the way you want it, click the Compile button in the lower right-hand corner. This will create all the files you want to distribute in the dist folder unless you have changed the name by checking the dist checkbox and editing the subsequent textbox. When it’s done compiling, GUI2Exe will ask you if you want to test your executable. Go ahead and hit Yes. If you receive any errors about missing modules, you can add them in the Python Modules or Python Packages section as appropriate. For this example, you shouldn’t have that issue though.
Now we’re ready to learn about creating the installer!
Let’s Make an Installer!¶
Now that we have an executable and a bunch of dependencies, how do we make an installer? For this chapter we’ll be using Inno Setup, but you could also use NSIS or a Microsoft branded installer. You will need to go to their website (http://www.jrsoftware.org/isdl.php), download the program and install it. Then run the program. You should see the main program along with the following dialog on top of it:
Choose the Create a new script using the Script Wizard option and then press the OK button. Click Next and you should see something like this:
Inno Setup Service
Fill this out however you like and click Next (I called mine wxForm). This next screen allows you to choose where you want the application to be installed by default. It defaults to Program Files which is fine. Click Next. Now you should see the following screen:
Browse to the executable you created to add it. Then click the Add file(s). button to add the rest. You can actually select all of the files except for the exe and hit OK. This is how mine turned out:
Now you’re ready to click Next. Make sure the Start Menu folder has the right name (in this case, wxForm) and continue. You can ignore the next two screens or experiment with them if you like. I’m not using a license or putting information files in to display to the user though. The last screen before finishing allows you to choose a directory to put the output into. I just left that empty since it defaults to where the executable is located, which is fine with this example. Click Next, Next and Finish. This will generate a full-fledged .iss file, which is what Inno Setup uses to turn your application into an installer. It will ask you if you’d like to go ahead and compile the script now. Go ahead and do that. Then it will ask if you’d like to save your .iss script. That’s a good idea, so go ahead and do that too. Hopefully you didn’t receive any errors and you can try out your new installer.
If you’re interested in learning about Inno’s scripting language, feel free to read Inno’s Documentation. You can do quite a bit with it. If you happen to make changes to your build script, you can rebuild your installer by going to the build menu and choosing the compile menu item.
Kill Process Program
Wrapping Up¶
Inno Setup Kill Process Before Install A Door
At this point, you now know how to create a real, live installer that you can use to install your application and any files it needs to run. This is especially handy when you have a lot of custom icons for your toolbars or a default database, config file, etc that you need to distribute with your application. Go back and try creating the installer again, but choose different options to see what else you can do. Experimenting is a great way to learn. Just make sure you always have a backup in case something goes wrong!