NSIS实现安装前先停止并卸载旧版

以下脚本会先找到正在运行的程序和服务,停止并删除服务,然后杀掉正在运行的程序进程

    ;检查服务是否存在
    SimpleSC::ExistsService  "${SVCHOST_EXE_NAME}"
    Pop $0
    ;停止并删除服务
    ${If} $0 == 0
        DetailPrint "停止正在运行的打印服务"
        SimpleSC::StopService "${SVCHOST_EXE_NAME}" 1 30
        DetailPrint "删除已安装的打印服务"
        SimpleSC::RemoveService "${SVCHOST_EXE_NAME}"
    ${EndIf}
    ;检查主程序是否运行,如果正在运行则进行终止
    nsProcess::_FindProcess "${ANALYST_EXE_NAME}"
    Pop $R0
    ${If} $R0 = 0
      DetailPrint "停止正在运行的主程序"
      nsProcess::_KillProcess "${ANALYST_EXE_NAME}"
      Pop $R0
    ${EndIf}
    ;检查升级程序是否运行,如果正在运行则进行终止
    nsProcess::_FindProcess "${UPDATE_EXE_NAME}"
    Pop $R0
    ${If} $R0 = 0
      DetailPrint "停止正在运行的升级程序"
      nsProcess::_KillProcess "${UPDATE_EXE_NAME}"
      Pop $R0
    ${EndIf}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

*

code