【问题标题】:How to install application as windows service using NSIS script如何使用 NSIS 脚本将应用程序安装为 Windows 服务
【发布时间】:2013-07-22 11:51:49
【问题描述】:

如何使用 NSIS 脚本将应用程序安装为 Windows 服务?

我在脚本Exec '"sc.exe" 中使用了这个命令,但安装后我在windows 服务中找不到任何与之相关的服务,请帮助我,谢谢。

【问题讨论】:

  • 您能否发布一段失败脚本的摘录,以显示Exec 语句的参数如何? makensis 输出中是否有任何警告?
  • ExecWait '"C:\Windows\System32\sc.EXE" "测试服务"' Exec $PROGRAMFILES\Example1\xxxx.EXE
  • 不要混淆服务名和显示名:Test Service,因为服务名不正确,因为空格
  • 请发布您在sc 命令中使用的exact 语法。要注册一个服务,你需要sc create ...sc service name不是一个工作命令
  • 我不能(不要)更新我的脚本它说错误关。你明白我的问题仪式吗??你可以把示例脚本发给我,希望对我有帮助,谢谢

标签: windows-services nsis


【解决方案1】:

也许 NSIS Simple Service plugin 可以帮助您。语法很简单

SimpleSC::InstallService "MyService" "My Service Display Name" "16" "2" "C:\MyPath\MyService.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)

这里的示例将服务安装为 ServiceType 自己的进程 + StartType 自动 + NoDependencies + 以系统帐户登录。 幻数的含义请参考随附的帮助。

wiki 显示 5 other methods 来处理 NSIS 服务。

【讨论】:

  • 我无法得到它 Seki... 安装后我的服务应该在 Windows 服务中。我可以通过使用该条目来停止或开始,请帮助我清楚地感谢......这是什么意思“C:\ MyPath \ MyService.exe”
  • 我已将 SimpleSC.dll 添加到 NSIS 文件夹中,并且我想在脚本中将此代码添加到哪个位置???SimpleSC::InstallService "MyService" "My Service Display Name" "16 " "2" "C:\MyPath\MyService.exe" "" "" "" Pop $0 ;返回错误代码 (0) 否则成功 (0)
  • @SujeethDamodharan 请注意,有一个功能可以为您查找错误代码。您还需要确保用户拥有“作为服务登录”的权利——这是另一个功能。阅读两者的示例文档
  • 我尝试使用这个示例,但我有问题插件未找到,无法调用 SimpleSC::StartService,抱歉我的英文不太好
  • 注意:简单服务插件不适用于 Unicode NSIS
【解决方案2】:

如 NSIS 网站所述,那里有 multiple plugins

对我来说这似乎没有必要复杂,所以我最终直接使用了sc 工具。一个命令很简单:

!define appName "theApp.exe"
!define displayName "My Awesome Service"
!define serviceName "MyAwesomeService"

ExecWait 'sc create ${serviceName} error= "severe" displayname= "${displayName}" type= "own" start= "auto" binpath= "$INSTDIR\${appName}"'

sc create 可用参数的完整列表here

【讨论】:

    【解决方案3】:

    以下是首先停止服务、卸载旧版本、删除表单注册表然后安装新副本的脚本。

    Section "Mobile Interface" 
    
      SimpleSC::StopService "MobileInterface" "1" "60"
      SimpleSC::RemoveService "MobileInterface"
      DeleteRegKey /ifempty HKLM "MobileInterface"
      RMDIR /r "$INSTDIR\MobileInterface\"
    
      SetOutPath "$INSTDIR\MobileInterface"
       # define what to install and place it in the output path
     File "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\"
    
     SimpleSC::InstallService "MobileInterface" "MobileInterface" "16" "2" "$INSTDIR\MobileInterface\NCS.Sentinel.MobileWebSvc.exe" "" "" ""
     Pop $0 ; returns an errorcode (<>0) otherwise success (0)
     SimpleSC::StartService "MobileInterface" "" "100"
    
    #WriteRegStr HKLM "D:\NCS.Sentinel\NCS.Sentinel.MobileWebSvc\bin\Release\NCS.Sentinel.MobileWebSvc.exe" 
    
      WriteUninstaller "$INSTDIR\Uninstall.exe"
    
      ; Store installation folder
      ;WriteRegStr HKCU "Software\Mobile Interface" "" $INSTDIR
    
    
    
    SectionEnd
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      相关资源
      最近更新 更多