Вот пример как я обрабатывал список программ-исключений Punto Switcher 3.2 (3.0 хранит списки программ-исключений по-другому).
Добавлял туда свою программу. Punto Switcher сначала закрывается, если он запущен.
Предварительно надо установить XML-plugin для NSIS -
http://nsis.sourceforge.net/XML_plug-in
Код:
!include "XML.nsh"
!include "LogicLib.nsh"
!include "WinVer.nsh"
!include "WordFunc.nsh"
!include WinMessages.nsh
...
!define WND_TITLE "Punto Switcher Main Window"
!define TO_MS 2000
!define SYNC_TERM 0x00100001
!macro TerminatePuntoSwitcher
Push $0 ; window handle
Push $1
Push $2 ; process handle
DetailPrint "Закрываем Пунто Свичер"
FindWindow $0 '' '${WND_TITLE}'
IntCmp $0 0 done
System::Call 'user32.dll::GetWindowThreadProcessId(i r0, *i .r1) i .r2'
System::Call 'kernel32.dll::OpenProcess(i ${SYNC_TERM}, i 0, i r1) i .r2'
SendMessage $0 ${WM_CLOSE} 0 0 /TIMEOUT=${TO_MS}
System::Call 'kernel32.dll::WaitForSingleObject(i r2, i ${TO_MS}) i .r1'
IntCmp $1 0 close
; MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION "Жестко закрываем" /SD IDYES IDYES terminate IDNO close
; System::Call 'kernel32.dll::CloseHandle(i r2) i .r1'
; Quit
terminate:
System::Call 'kernel32.dll::TerminateProcess(i r2, i 0) i .r1'
close:
System::Call 'kernel32.dll::CloseHandle(i r2) i .r1'
done:
Pop $2
Pop $1
Pop $0
!macroend
...
Function .onInstSuccess
...
!insertmacro TerminatePuntoSwitcher
${xml::LoadFile} "$PROFILE\AppData\Roaming\Yandex\Punto Switcher\User Data\preferences.xml" $0
${If} $0 == -1
${xml::LoadFile} "$PROFILE\Application Data\Yandex\Punto Switcher\User Data\preferences.xml" $0
${EndIf}
${If} $0 = 0 ; если загрузили настройки
${xml::GotoPath} "/PuntoSwitcherSettings/ProgramsExceptions" $0
${If} $0 == 0
${xml::GetText} $0 $1
${If} $0 == ''
${xml::SetText} "$INSTDIR\Stamina.exe" $1
${xml::SaveFile} "" $0
${Else}
${WordFind} $0 "$INSTDIR\Stamina.exe" "E#" $R1
IfErrors 0 end ; если ошибка (то есть не нашли), то переходим к след. строке, а иначе к end:
${xml::SetText} "$0,$INSTDIR\Stamina.exe" $1
${xml::SaveFile} "" $0
end:
${EndIf}
${EndIf}
${EndIf}
${xml::Unload}
...
FunctionEnd