如何 运行 以管理员身份使用 NSIS 和 NSSM 启动程序?
how to run a program on start up as an administrator using NSIS and NSSM?
我正在使用 nsis 为 windows 创建安装程序,我正在使用 NSSM 运行 应用程序。
我安装服务器时一切正常,但问题是我的服务器需要 运行 作为管理员才能使用某些功能。我通过手动转到“服务”然后登录选项卡输入我的用户名和密码解决了我的问题。
但是,我不想那样做,我希望安装程序要求用户在安装之后或安装之前立即输入他的管理员凭据。
提前感谢您的时间和努力
根据他们的文档,NSSM 已经知道如何设置服务凭据,因此您只需要自定义页面即可将它们结合在一起:
!include LogicLib.nsh
!include nsDialogs.nsh
!define MYSERVICE "FooBarBaz"
Var SvcUser
Var SvcPass
Page Directory
Page Custom MyServiceCredCreate MyServiceCredLeave ": Service credentials "
Page InstFiles
Function MyServiceCredCreate
nsDialogs::Create 1018
Pop [=10=]
${IfThen} [=10=] == error ${|} Abort ${|}
${NSD_CreateLabel} 0 0 100% 12u "Username:"
Pop [=10=]
${NSD_CreateText} 0 13u 100% 12u "$SvcUser"
Pop
${NSD_CreateLabel} 0 26u 100% 12u "Password:"
Pop [=10=]
${NSD_CreatePassword} 0 39u 100% 12u "$SvcPass"
Pop
nsDialogs::Show
FunctionEnd
Function MyServiceCredLeave
${NSD_GetText} $SvcUser
${NSD_GetText} $SvcPass
${If} $SvcUser == ""
MessageBox MB_ICONSTOP "Must provide a username!"
Abort
${EndIf}
FunctionEnd
Section
SetOutPath $InstDir
File "myservicething.exe"
File "nssm.exe"
nsExec::Exec '"$InstDir\nssm.exe" install "${MYSERVICE}" "$InstDir\myservicething.exe"'
Pop [=10=]
nsExec::Exec '"$InstDir\nssm.exe" set "${MYSERVICE}" ObjectName $SvcUser "$SvcPass"'
Pop [=10=]
SectionEnd
我正在使用 nsis 为 windows 创建安装程序,我正在使用 NSSM 运行 应用程序。
我安装服务器时一切正常,但问题是我的服务器需要 运行 作为管理员才能使用某些功能。我通过手动转到“服务”然后登录选项卡输入我的用户名和密码解决了我的问题。
但是,我不想那样做,我希望安装程序要求用户在安装之后或安装之前立即输入他的管理员凭据。
提前感谢您的时间和努力
根据他们的文档,NSSM 已经知道如何设置服务凭据,因此您只需要自定义页面即可将它们结合在一起:
!include LogicLib.nsh
!include nsDialogs.nsh
!define MYSERVICE "FooBarBaz"
Var SvcUser
Var SvcPass
Page Directory
Page Custom MyServiceCredCreate MyServiceCredLeave ": Service credentials "
Page InstFiles
Function MyServiceCredCreate
nsDialogs::Create 1018
Pop [=10=]
${IfThen} [=10=] == error ${|} Abort ${|}
${NSD_CreateLabel} 0 0 100% 12u "Username:"
Pop [=10=]
${NSD_CreateText} 0 13u 100% 12u "$SvcUser"
Pop
${NSD_CreateLabel} 0 26u 100% 12u "Password:"
Pop [=10=]
${NSD_CreatePassword} 0 39u 100% 12u "$SvcPass"
Pop
nsDialogs::Show
FunctionEnd
Function MyServiceCredLeave
${NSD_GetText} $SvcUser
${NSD_GetText} $SvcPass
${If} $SvcUser == ""
MessageBox MB_ICONSTOP "Must provide a username!"
Abort
${EndIf}
FunctionEnd
Section
SetOutPath $InstDir
File "myservicething.exe"
File "nssm.exe"
nsExec::Exec '"$InstDir\nssm.exe" install "${MYSERVICE}" "$InstDir\myservicething.exe"'
Pop [=10=]
nsExec::Exec '"$InstDir\nssm.exe" set "${MYSERVICE}" ObjectName $SvcUser "$SvcPass"'
Pop [=10=]
SectionEnd