无法使用NSIS运行命令提示符命令

时间:2015-02-17 06:21:29

标签: nsis

我想使用NSSM运行服务,从命令提示符(以管理员身份运行)的方式运行。命令提示符中使用的命令是:

# Command Prompt commands
C:\Windows\system32>cd C:\Users\D-002\Downloads\nssm-2.24\win64

C:\Users\D-002\Downloads\nssm-2.24\win64>
nssm install TestService "C:\Program Files (x86)\CodeBlocks\Testing Projects\TestServiceProgram\bin\Debug\TestServiceProgram.exe"
Service "TestService" installed successfully!

但我希望使用NSIS实现相同的功能。运行以下脚本不会创建TestService。

# NSIS script
; name the installer

OutFile "Installer.exe"

; default section start; every NSIS script has at least one section.

Section

;nssm folder is placed in same folder where Installer.exe is created

ExecWait 'cd "$EXEDIR\nssm\win64"'
ExecWait 'nssm install TestService "$EXEDIR\TestServiceProgram.exe"'

; default section end

SectionEnd

由于我对NSIS没有先验知识,如果有人能指出,我做错了什么或错过了什么?

1 个答案:

答案 0 :(得分:1)

  1. 检查服务是否已创建到服务列表中。已创建但未运行?

  2. 如果已创建但未运行,请记住使用System32作为工作目录执行服务,此处必须放置最终配置文件。

  3. 您可以使用SimpleSC插件(http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin)安装服务:

    这是我的代码:

    Section "Install Service"
    SimpleSC::ExistsService "MyService" ;
    MyService
    pop $0
    
    ${If} $0 == "0" ;
    

    {

      SimpleSC::StopService "MyService"
      DetailPrint "Service found"
    

    }

        ${Endif}
    
      DetailPrint "Installing My"
      SimpleSC::InstallService  "MyService" \
                                "My Service Description" \
                                16 \
                                2 \
                                "$ServiceFolder\MyService.exe" \
                                "" \
                                "" \
                                "" \
                                ""
    
      SimpleSC::SetServiceDescription "MyService" "MyService description"
    
      DetailPrint "Installation of MyService completed"
      SimpleSC::StartService MyService"
      DetailPrint "Service started."
    
    SectionEnd