使用NSIS创建和控制服务安装应用程序时,安装失败
我的要求是,当使用NSIS安装应用程序时,应该安装和控制服务(启动和停止) 为此,首先我下载了“NSIS_Simple_Service_Plugin_1.30”,并将SimpleSC.dll放在“x86 ansi”目录中 我在“节”下写了下面的代码使用NSIS创建和控制服务安装应用程序时,安装失败,nsis,Nsis,我的要求是,当使用NSIS安装应用程序时,应该安装和控制服务(启动和停止) 为此,首先我下载了“NSIS_Simple_Service_Plugin_1.30”,并将SimpleSC.dll放在“x86 ansi”目录中 我在“节”下写了下面的代码 ;安装服务: SimpleSC::InstallService“testserv”测试服务Testtwo“16”2 E:\Source\Release\testserv.exe“” 流行音乐0美元;返回错误代码(0),否则返回成功(0) IntCmp
;安装服务:
SimpleSC::InstallService“testserv”测试服务Testtwo“16”2 E:\Source\Release\testserv.exe“”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
IntCmp$0+3
MessageBox MB_OK | MB_ICONSTOP“testserv安装失败:无法创建服务。”
中止
SimpleESC::SetServiceDescription“testserv”“测试项目服务”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
; 我们不在乎结果。
; 使用NSIS简单服务插件启动服务
SimpleSC::StartService“testserv”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
IntCmp$0+3
MessageBox MB_OK | MB_ICONSTOP“testserv安装失败:无法启动服务。”
中止
当我测试安装程序时,它从我保存的MessageBox中显示消息“testserv安装失败:无法创建服务”
; ServiceTest.nsi
;
;
; It will install ServiceTest.nsi into a directory that the user selects.
;--------------------------------
; The name of the installer in the path C:\Program Files\Registry
Name "ServiceTest"
; The file to write in the path E:\Source\NULLSOFT\src
OutFile "ServiceTest.exe"
; The default installation directory in the path C:\Program Files\ServiceTest
InstallDir $PROGRAMFILES\ServiceTest
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically) It shows the path the path C:\Program Files\ServiceTest
InstallDirRegKey HKLM "Software\ServiceTest" "Install_Dir"
; Request application privileges for Windows Vista
; Below line is to check the administrative permissions
RequestExecutionLevel admin
; Below is the include file to check the conditions (If and else)
!include LogicLib.nsh
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
;--------------------------------
;Installer Functions
Function .onInit
UserInfo::GetAccountType
pop $0
${If} $0 != "admin"
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${Else}
MessageBox MB_OK "User is having Administrative Permissions"
${EndIf}
FunctionEnd
;--------------------------------
; The stuff to install
Section "ServiceTest (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\ServiceTest
SetOutPath $INSTDIR
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\ServiceTest "Install_Dir" "$INSTDIR"
WriteRegStr HKLM SOFTWARE\ServiceTest\Dialog "TestDlg" "0"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "DisplayName" "ServiceTest"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "NoRepair" 1
WriteUninstaller "uninstall.exe"
;InstallServices:
SimpleSC::InstallService "testserv" "Test Service Testtwo" "16" "2" "E:\Source\testserv\Release\testserv.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv installation failed: could not create service."
Abort
SimpleSC::SetServiceDescription "testserv" "Test service."
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
; We don't care about the result.
; Start a service using NSIS Simple Service Plugin
SimpleSC::StartService "tetserv" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv installation failed: could not start service."
Abort
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$INSTDIR\ServiceTest"
CreateShortcut "$INSTDIR\ServiceTest\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortcut "$INSTDIR\ServiceTest\ServiceTest (MakeNSISW).lnk" "$INSTDIR\ServiceTest.nsi" "" "$INSTDIR\ServiceTest.nsi" 0
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest"
DeleteRegKey HKLM SOFTWARE\ServiceTest
; Remove files and uninstaller
Delete $INSTDIR\ServiceTest.nsi
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$INSTDIR\ServiceTest\*.*"
; Remove directories used
RMDir "$INSTDIR\ServiceTest"
RMDir "$INSTDIR"
; To Uninstall the Service
; Stop the service using NSIS Simple Service Plugin
SimpleSC::ExistsService "testserv"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +1
; Stop the service using NSIS Simple Service Plugin
SimpleSC::StopService "tesserv"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv uninstallation failed: could not stop service."
Abort
; Stop the service using NSIS Simple Service Plugin
SimpleSC::RemoveService "testserv"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv uninstallation failed: could not remove service."
Abort
SectionEnd
;服务测试
;
;
; 它将ServiceTest.nsi安装到用户选择的目录中。
;--------------------------------
; 路径C:\Program Files\Registry中安装程序的名称
名称“ServiceTest”
; 要在路径E:\Source\NULLSOFT\src中写入的文件
输出文件“ServiceTest.exe”
; 路径C:\Program Files\ServiceTest中的默认安装目录
InstallDir$PROGRAMFILES\ServiceTest
; 注册表项以检查目录(因此,如果您再次安装,它将
;自动覆盖旧的路径)它显示路径C:\Program Files\ServiceTest
InstallDirRegKey HKLM“软件\服务测试”“安装目录”
; 请求Windows Vista的应用程序权限
; 下一行用于检查管理权限
RequestExecutionLevel管理员
; 下面是检查条件的包含文件(If和else)
!包括LogicLib.nsh
;--------------------------------
; 页
页面组件
页面目录
页面文件
未登录未登录确认
未屏蔽文件
;--------------------------------
;--------------------------------
;安装程序功能
函数。onInit
UserInfo::GetAccountType
流行音乐$0
${If}$0!=“管理员”
MessageBox mb_iconstop“需要管理员权限!”
设置错误级别740;错误\u需要仰角\u
退出
${Else}
MessageBox MB_OK“用户具有管理权限”
${EndIf}
功能端
;--------------------------------
; 要安装的东西
“服务测试(必需)”部分
反渗透
; 将输出路径设置为安装目录。以下是路径C:\Program Files\ServiceTest
SetOutPath$INSTDIR
; 将安装路径写入注册表
WriteRegStr HKLM SOFTWARE\ServiceTest“安装目录”$INSTDIR
WriteRegStr HKLM SOFTWARE\ServiceTest\Dialog“TestDlg”0
; 编写Windows的卸载密钥
WriteRegStr HKLM“软件\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest”“显示名称”“ServiceTest”
WriteRegStr HKLM“软件\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest”“卸载字符串”“$INSTDIR\Uninstall.exe”
WriteRegWord HKLM“软件\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest”“NoModify”1
WriteRegWord HKLM“Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest”“NoRepair”1
WriteUninstiller“uninstall.exe”
;安装服务:
SimpleSC::InstallService“testserv”测试服务Testtwo“16”2 E:\Source\testserv\Release\testserv.exe“”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
IntCmp$0+3
MessageBox MB_OK | MB_ICONSTOP“testserv安装失败:无法创建服务。”
中止
SimpleESC::SetServiceDescription“testserv”“测试服务”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
; 我们不在乎结果。
; 使用NSIS简单服务插件启动服务
SimpleSC::StartService“tetserv”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
IntCmp$0+3
MessageBox MB_OK | MB_ICONSTOP“testserv安装失败:无法启动服务。”
中止
分段结束
; 可选部分(可由用户禁用)
“开始菜单快捷方式”部分
CreateDirectory“$INSTDIR\ServiceTest”
创建快捷方式“$INSTDIR\ServiceTest\Uninstall.lnk”“$INSTDIR\Uninstall.exe”“$INSTDIR\Uninstall.exe”0
创建快捷方式“$INSTDIR\ServiceTest\ServiceTest(MakeNSISW).lnk”“$INSTDIR\ServiceTest.nsi”“$INSTDIR\ServiceTest.nsi”0
分段结束
;--------------------------------
; 卸载程序
“卸载”部分
; 删除注册表项
DeleteRegKey HKLM“软件\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest”
DeleteRegKey HKLM软件\ServiceTest
; 删除文件和卸载程序
删除$INSTDIR\ServiceTest.nsi
删除$INSTDIR\uninstall.exe
; 删除快捷方式(如果有)
删除“$INSTDIR\ServiceTest\*.*”
; 删除使用的目录
RMDir“$INSTDIR\ServiceTest”
RMDir“$INSTDIR”
; 卸载该服务
; 使用NSIS简单服务插件停止服务
SimpleSC::ExistsService“testserv”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
IntCmp$0+1
; 使用NSIS简单服务插件停止服务
SimpleSC::StopService“tesserv”
流行音乐0美元;返回错误代码(0),否则返回成功(0)
IntCmp$0+3
消息框MB|U OK | M
; ServiceTest.nsi
;
;
; It will install ServiceTest.nsi into a directory that the user selects.
;--------------------------------
; The name of the installer in the path C:\Program Files\Registry
Name "ServiceTest"
; The file to write in the path E:\Source\NULLSOFT\src
OutFile "ServiceTest.exe"
; The default installation directory in the path C:\Program Files\ServiceTest
InstallDir $PROGRAMFILES\ServiceTest
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically) It shows the path the path C:\Program Files\ServiceTest
InstallDirRegKey HKLM "Software\ServiceTest" "Install_Dir"
; Request application privileges for Windows Vista
; Below line is to check the administrative permissions
RequestExecutionLevel admin
; Below is the include file to check the conditions (If and else)
!include LogicLib.nsh
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;--------------------------------
;--------------------------------
;Installer Functions
Function .onInit
UserInfo::GetAccountType
pop $0
${If} $0 != "admin"
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Quit
${Else}
MessageBox MB_OK "User is having Administrative Permissions"
${EndIf}
FunctionEnd
;--------------------------------
; The stuff to install
Section "ServiceTest (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\ServiceTest
SetOutPath $INSTDIR
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\ServiceTest "Install_Dir" "$INSTDIR"
WriteRegStr HKLM SOFTWARE\ServiceTest\Dialog "TestDlg" "0"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "DisplayName" "ServiceTest"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest" "NoRepair" 1
WriteUninstaller "uninstall.exe"
;InstallServices:
SimpleSC::InstallService "testserv" "Test Service Testtwo" "16" "2" "E:\Source\testserv\Release\testserv.exe" "" "" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv installation failed: could not create service."
Abort
SimpleSC::SetServiceDescription "testserv" "Test service."
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
; We don't care about the result.
; Start a service using NSIS Simple Service Plugin
SimpleSC::StartService "tetserv" ""
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv installation failed: could not start service."
Abort
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$INSTDIR\ServiceTest"
CreateShortcut "$INSTDIR\ServiceTest\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortcut "$INSTDIR\ServiceTest\ServiceTest (MakeNSISW).lnk" "$INSTDIR\ServiceTest.nsi" "" "$INSTDIR\ServiceTest.nsi" 0
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ServiceTest"
DeleteRegKey HKLM SOFTWARE\ServiceTest
; Remove files and uninstaller
Delete $INSTDIR\ServiceTest.nsi
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$INSTDIR\ServiceTest\*.*"
; Remove directories used
RMDir "$INSTDIR\ServiceTest"
RMDir "$INSTDIR"
; To Uninstall the Service
; Stop the service using NSIS Simple Service Plugin
SimpleSC::ExistsService "testserv"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +1
; Stop the service using NSIS Simple Service Plugin
SimpleSC::StopService "tesserv"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv uninstallation failed: could not stop service."
Abort
; Stop the service using NSIS Simple Service Plugin
SimpleSC::RemoveService "testserv"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
IntCmp $0 0 +3
MessageBox MB_OK|MB_ICONSTOP "testserv uninstallation failed: could not remove service."
Abort
SectionEnd
!include LogicLib.nsh
Section
SetOutPath $InstDir
File "E:\Code\PCPE\mainserv\Release\mainserv.exe"
SimpleSC::InstallService "mainserv" "UPS Service Testtwo" "16" "2" '"$InstDir\mainserv.exe"' "" "" ""
Pop $0
${If} $0 <> 0
MessageBox MB_ICONSTOP "InstallService failed, error $0"
Abort
${EndIf}
...
SectionEnd