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

Unable to run command prompt commands using 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. 检查服务是否被创建到服务列表中。已创建但未创建 运行?

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

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

这是我的代码:

Section "Install Service"
SimpleSC::ExistsService "MyService" ;
MyService
pop [=10=]

${If} [=10=] == "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