@@ -32,6 +32,7 @@ DisableProgramGroupPage=yes
3232LicenseFile = ..\LICENSE.txt
3333OutputBaseFilename = AutoAudioSwitcher-Setup
3434PrivilegesRequired = lowest
35+ RestartApplications = no
3536ShowLanguageDialog = auto
3637SolidCompression = yes
3738VersionInfoProductTextVersion = {#ProductVersion}
@@ -49,11 +50,53 @@ Source: "..\publish\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs cr
4950Name : " {userstartup}\Auto Audio Switcher" ; Filename : " {app} \AutoAudioSwitcher.exe"
5051
5152[Run]
52- Filename : " {app} \AutoAudioSwitcher.exe" ; Flags : nowait postinstall
53+ Filename : " {app} \AutoAudioSwitcher.exe" ; Description : " {cm:LaunchProgram,Auto Audio Switcher} " ; Flags : nowait postinstall
5354
5455[Code]
56+ const
57+ APP_MUTEX = ' f09f929b-e98f-a1e9-9fb3-e383aae383b3' ;
58+ WINDOW_NAME = ' Auto Audio Switcher' ;
59+ APP_EXE = ' AutoAudioSwitcher.exe' ;
60+ WM_CLOSE = 16 ;
61+
5562function InitializeSetup : Boolean;
5663begin
5764 Dependency_AddDotNet100Desktop;
5865 Result := True;
5966end ;
67+
68+ procedure CloseApplication ;
69+ var
70+ Hwnd: HWND;
71+ Timeout: Integer;
72+ ErrorCode: Integer;
73+ begin
74+ if not CheckForMutexes(APP_MUTEX) then
75+ exit;
76+ Hwnd := FindWindowByWindowName(WINDOW_NAME);
77+ if Hwnd <> 0 then
78+ begin
79+ SendMessage(Hwnd, WM_CLOSE, 0 , 0 );
80+ Timeout := 100 ; // 10s
81+ while (Timeout > 0 ) and CheckForMutexes(APP_MUTEX) do
82+ begin
83+ Sleep(100 );
84+ Timeout := Timeout - 1 ;
85+ end ;
86+ end ;
87+ if CheckForMutexes(APP_MUTEX) then
88+ Exec(' taskkill.exe' , ' /f /im ' + APP_EXE, ' ' , SW_HIDE, ewWaitUntilTerminated, ErrorCode);
89+ end ;
90+
91+ procedure CurUninstallStepChanged (CurUninstallStep: TUninstallStep);
92+ var
93+ OriginalCaption: String;
94+ begin
95+ if CurUninstallStep = usUninstall then
96+ begin
97+ OriginalCaption := UninstallProgressForm.StatusLabel.Caption;
98+ UninstallProgressForm.StatusLabel.Caption := SetupMessage(msgStatusClosingApplications);
99+ CloseApplication;
100+ UninstallProgressForm.StatusLabel.Caption := OriginalCaption;
101+ end ;
102+ end ;
0 commit comments