이슈에 올라온 기능을 처리해보자
이 NSIS 스크립트에 abc.exe가 이미 실행 중인 경우, 사용자가 이를 종료하고 설치를 계속할지 묻는 기능을 추가하는 기능
(현재 실행 중인 프로세스를 찾는 플러그인은 FindProcess 와 nsProcess가 있으며, 본인은 FindProcess를 이용하였음)
Processes::FindProcess vs. nsProcess::FindProcess vs. FindProcDLL - NSIS Forums
Processes::FindProcess vs. nsProcess::FindProcess vs. FindProcDLL - NSIS Forums
nsnb 20th September 2010 17:48 UTC Processes::FindProcess vs. nsProcess::FindProcess vs. FindProcDLL I noticed that there are multiple plug-ins with similar functionality: http://nsis.sourceforge.net/FindProcDLL_plug-in http://nsis.sourceforge.net/Proce
nsis-dev.github.io
[주요 로직]
사용자에게 종료 여부 묻기: 만약 abc.exe가 실행 중이라면 MessageBox로 사용자에게 프로그램 종료 후 설치를 계속할 것인지 묻고,
- 사용자가 "Yes"를 선택하면 해당 프로세스를 강제 종료하고 설치를 계속합니다.
- 사용자가 "No"를 선택하면 설치를 중단(Abort)한다
. Function .onInit은 설치 프로그램이 처음 실행될 때 호출되는 함수로, 설치 과정 시작 전에 필요한 초기 작업을 수행하므로, Function .onInit 함수 안에 로직을 추가해야 한다.
FindprocDLL 다운 받는 곳
FindProcDLL plug-in - NSIS
FindProcDLL ©2003 by iceman_k (Sunil Kamath), based upon the FIND_PROC_BY_NAME function written by Ravi Kochhar (http://www.physiology.wisc.edu/ravi/) Links FindProc.zip (24 KB) Optimized by size binaries of FindProcDll and KillProcDll are available here:
nsis.sourceforge.io
Programfiles\NSIS\Plugins , Include 여기 경로에다가내가 넣으려는 FindProcDLL.dll 파일을 넣어 줘야한다.

코드
;!addplugindir "${NSISDIR}\\Plugins"
;!addincludedir "${NSISDIR}\\Include"
;!include "FindProcDLL.nsh"
Function .onInit
; abc.exe 실행 중인지 확인
nsExec::ExecToStack "tasklist /FI 'IMAGENAME eq abc.exe' | find /I 'abc.exe'"
Pop $0
StrCmp $0 0 +2
Goto askUser
; abc.exe가 실행 중이지 않음 -> 설치 진행
Goto continueInstall
askUser:
MessageBox MB_YESNO "abc.exe is already running. Do you want to close it and continue the installation?" IDYES endTask IDNO abortInstall
endTask:
; 실행 중인 abc.exe 프로세스 종료
nsExec::Exec "taskkill /F /IM abc.exe"
Goto continueInstall
abortInstall:
Abort ; 설치 중단
continueInstall:
; 기존의 onInit 로직 추가
Push $R1
ReadRegStr $R1 HKLM "SOFTWARE\\..." CurrentMajorVersionNumber
StrLen $0 $R1
${If} $0 == 0
MessageBox MB_OK "Not Windows Operation System!"
Quit
${EndIf}
...
; 이후 기존의 .onInit 함수 로직
FunctionEnd
abc.exe가 실행 중일 때, 설치 전에 사용자에게 종료 여부를 물어보고 처리
[에러]UTF-8 인코딩 실패 : 스크립트에 한글이 들어가면 안된다. → "abc.exe is already running. Do you want to close it and continue the installation?" 로 변경
[에러]레이블 이름 변경 : continueInstall 이 이미 함수 내에 있으면, 레이블 이름이 겹치면 안된다
→ proceedInstall 로 변경
; Push a variable to store values
Push $R1
; Check if Windows OS
ReadRegStr $R1 HKLM "SOFTWARE\\Microsoft\\..." CurrentMajorVersionNumber
StrLen $0 $R1
${If} $0 == 0
MessageBox MB_OK "Not a Windows Operating System!"
Quit
${EndIf}
; Check if abc.exe is running
FindProcDLL::FindProc "abc.exe"
; MessageBox MB_OK "[$R0]"
StrCmp $R0 0 noProcessRunning
MessageBox MB_YESNO "abc.exe is already running. Do you want to close it and continue the installation?" IDNO cancelInstallation
FindProcDLL::KillProc "abc.exe"
Goto noProcessRunning
cancelInstallation:
Abort
noProcessRunning:
//나머지 구현
[디버깅]
FindProcDLL::FindProc "abc.exe"
MessageBox MB_OK "[$R0]"
StrCmp $R0 0 noProcessRunning
→ FindproDLL 이 실행중인 프로세스를 잘 찾는 지 확인하는 코드를 추가한다.
공식 문서에서 샘플코드에 대한 각 숫자의 의미를 알수있다,
FindProcDLL plug-in - NSIS
FindProcDLL ©2003 by iceman_k (Sunil Kamath), based upon the FIND_PROC_BY_NAME function written by Ravi Kochhar (http://www.physiology.wisc.edu/ravi/) Links FindProc.zip (24 KB) Optimized by size binaries of FindProcDll and KillProcDll are available here:
nsis.sourceforge.io

출력 성공

'인턴 기록' 카테고리의 다른 글
[인턴] 91일차 wfp버그 : setup창 뜨기 전 cmd창이 뜨는 오류 (0) | 2024.12.03 |
---|---|
[인턴] 43일차 터미널 메세지 동시 발송 (0) | 2024.10.17 |
파일 탐색해서 파일 내용 바꾸기(python) (1) | 2024.09.25 |
NSIS 도구 활용하여 기존 설치 파일(exe 파일) 수정하기 (0) | 2024.09.25 |
관리자 권한 없이 프로그램 업데이트 코드 짜기 (C언어) (2) | 2024.09.20 |