Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop process if already running #84

Merged
merged 3 commits into from
Dec 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions templates/installer.nsi.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Name "${APP_NAME}"
!define MUI_ICON "icon.ico"
!define MUI_UNICON "icon.ico"


!addplugindir .
!include "nsProcess.nsh"

Expand All @@ -28,11 +29,25 @@ InstallDir "$PROGRAMFILES\${APP_NAME}\"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"

!macro CheckAppRunning MODE
${nsProcess::FindProcess} "${APP_NAME}.exe" $R0
${If} $R0 == 0
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${APP_NAME} is running. $\r$\nClick OK to close it and continue with ${MODE}." /SD IDCANCEL IDOK doStopProcess
Abort
doStopProcess:
DetailPrint "Closing running ${APP_NAME} ..."
${nsProcess::KillProcess} "${APP_NAME}.exe" $R0
DetailPrint "Waiting for ${APP_NAME} to close."
Sleep 2000
${EndIf}
${nsProcess::Unload}
!macroend

# default section start
Section
SetShellVarContext all

!insertmacro CheckAppRunning "install"
# delete the installed files
RMDir /r $INSTDIR

Expand Down Expand Up @@ -67,16 +82,7 @@ SectionEnd
# create a section to define what the uninstaller does
Section "Uninstall"

${nsProcess::FindProcess} "${APP_NAME}.exe" $R0

${If} $R0 == 0
DetailPrint "${APP_NAME} is running. Closing it down..."
${nsProcess::KillProcess} "${APP_NAME}.exe" $R0
DetailPrint "Waiting for ${APP_NAME} to close."
Sleep 2000
${EndIf}

${nsProcess::Unload}
!insertmacro CheckAppRunning "uninstall"

SetShellVarContext all

Expand Down