NSIS安裝或卸載時檢查程序是否正在運行

轉載:http://www.javashuo.com/article/p-qfkfpeof-y.htmlhtml

轉載:https://www.gongzi.org/nsisbuildqqstop.htmlui

轉載:http://blog.sina.com.cn/s/blog_6aeaee7e0100smrn.html(若是當前程序正在運行,殺掉進程繼續安裝或者卸載,給了啓發)spa

轉載:https://blog.csdn.net/llmys/article/details/88618177(教程).net

使用場景:插件

    若是咱們要安裝或升級程序時,軟件正在運行,這個時候安裝文件確定會替換失敗,友好的操做是提示用戶結束正在運行的程序3d

準備工做:code

1. 檢測程序是否在運行,須要使用插件FindProcDLL.dll,殺死當前運行的進程,須要使用插件KillProcDLL.dllhtm

2.這兩個插件的下載地址:http://nsis.sourceforge.net/FindProcDLL_plug-in
blog

3. 放到C:\Program Files (x86)\NSIS\Plugins裏面教程

 

 4. 添加腳本

; ------ 安裝前檢查程序是否正在運行
Function .onInit
FindProcDLL::FindProc "AppSetup.exe"
   Pop $R0
   IntCmp $R0 1 0 no_run
   MessageBox MB_OKCANCEL|MB_ICONSTOP  "安裝程序檢測到 ${PRODUCT_NAME} 正在運行。$\r$\n$\r$\n點擊 「肯定」 強制關閉${PRODUCT_NAME},繼續安裝。$\r$\n點擊 「取消」 退出安裝程序。" IDCANCEL Exit
   KillProcDLL::KillProc "AppSetup.exe"
   Sleep 1000
   FindProcDLL::FindProc "AppSetup.exe"
   Pop $R0
   IntCmp $R0 1 0 no_run
   Exit:
   Quit
   no_run:
FunctionEnd

 

 

; ------ 卸載前檢查程序是否正在運行
Function un.onInit
    MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您確實要徹底移除${PRODUCT_NAME},及其全部的組件?" IDYES +2
  Abort
    ;檢測程序是否運行
  FindProcDLL::FindProc "AppSetup.exe"
   Pop $R0
   IntCmp $R0 1 0 no_run
   KillProcDLL::KillProc "AppSetup.exe"
   Sleep 1000
   FindProcDLL::FindProc "AppSetup.exe"
   Pop $R0
   IntCmp $R0 1 0 no_run
   Quit
   no_run:
FunctionEnd
相關文章
相關標籤/搜索