原文連接 http://www.flighty.cn/html/bushu/20110402_115.htmlhtml
若是咱們要安裝或升級的程序正在運行,文件確定會替換失敗,如下代碼能夠提示用戶結束正在運行的程序。ui
須要使用插件FindProcDLL.dll,下載路徑:http://nsis.sourceforge.net/FindProcDLL_plug-in
spa
http://files.cnblogs.com/files/z5337/FindProc.zip.net
http://files.cnblogs.com/files/z5337/KillProcDll%26FindProcDll.zip插件
開始安裝時檢查flighty.exe是否正在運行:code
Function .onInit ;關閉進程 Push $R0 CheckProc: Push "flighty.exe" ProcessWork::existsprocess Pop $R0 IntCmp $R0 0 Done MessageBox MB_OKCANCEL|MB_ICONSTOP "安裝程序檢測到 ${PRODUCT_NAME} 正在運行。$\r$\n$\r$\n點擊 「肯定」 強制關閉${PRODUCT_NAME},繼續安裝。$\r$\n點擊 「取消」 退出安裝程序。" IDCANCEL Exit Push "flighty.exe" Processwork::KillProcess Sleep 1000 Goto CheckProc Exit: Abort Done: Pop $R0 FunctionEnd
開始卸載時檢查flighty.exe是否正在運行:htm
Function un.onInit MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您確實要徹底移除 $(^Name) ,及其全部的組件?" IDYES +2 Abort ;檢測程序是否運行 FindProcDLL::FindProc "flighty.exe" Pop $R0 IntCmp $R0 1 0 no_run MessageBox MB_ICONSTOP "卸載程序檢測到 ${PRODUCT_NAME} 正在運行,請關閉以後再卸載!" Quit no_run: FunctionEnd
順便提一句:若是你的程序被360誤殺過,能夠用這個提示用戶關閉360才能夠進行安裝。blog