NSIS 脚本不显示服务状态
NSIS script doesn't display service status
我在脚本末尾创建了一个部分,它应该显示我的服务状态,但在执行后没有显示消息框。
可能是什么原因?
Section "Create Service"
ExecShellWait '' 'sc.exe' 'create myservice error= "severe" displayname= "myservice" type= "own" start= "auto" binpath= "$INSTDIR\MyService.exe"' SW_HIDE
SectionEnd
Section "Start Service"
ExecShellWait '' 'sc.exe' 'start myservice' SW_HIDE
SectionEnd
Section "Ensure Running"
StrCpy $R0 '"$SYSDIR\cmd.exe" /c "sc QUERY myservice | FIND /C "RUNNING""'
nsExec::ExecToStack '$R0'
Pop $R1 # contains return code
Pop $R2 # contains output
${If} $R1 == "0"
DetailPrint "checking if command is success"
${If} $R2 == "1"
MessageBox mb_ok "myservice is Running" # it's running
${Else}
MessageBox mb_ok "Not Running" # it's not running
${EndIf}
${Else}
DetailPrint "command failed"
${EndIf}
SectionEnd ```
nsExec::ExecToStack /OEM '$R0' didn't change anything. During installation it rushes to finish page after sc exec ..Do I need to add additional page page here ?
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ..\license.rtf
; Page custom pageRegistration
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
没有看到输出,我只能猜测存在某种 Unicode 问题。
将 nsExec::ExecToStack '$R0'
更改为 nsExec::ExecToStack /OEM '$R0'
。
也就是说,我不知道 运行 字符串是否总是英文的。您可以使用 NSIS wiki 上的几个服务插件和宏。
或者你可以使用这个:
!include "LogicLib.nsh"
!include "Win\COM.nsh"
!include "Win\Propkey.nsh"
Function IsServiceRunning
Exch [=10=]
Push
StrCpy [=10=]
!insertmacro ComHlpr_CreateInProcInstance {13709620-C279-11ce-A49E-444553540000} {A4C6892C-3BA9-11D2-9DEA-00C04FB16162} r0 "" ; IE5+?
${If} [=10=] P<> 0
System::Call "[=10=]->36(wr1,@r1)i.s"
${IUnknown::Release} [=10=] ""
Pop [=10=]
${If} [=10=] >= 0
StrCpy [=10=] 0
Push
${V_GetVT} r2
${V_GetBOOL} r1
${If} = ${VT_BOOL}
${AndIf} <> ${VARIANT_FALSE}
StrCpy [=10=] 1
${EndIf}
Pop
${Else}
StrCpy [=10=] 0
${EndIf}
${EndIf}
Pop
Exch [=10=]
FunctionEnd
Section "Example"
Push "RemoteRegistry"
Call IsServiceRunning
Pop [=10=]
DetailPrint "RemoteRegistry running=[=10=]"
Push "Themes"
Call IsServiceRunning
Pop [=10=]
DetailPrint "Themes running=[=10=]"
SectionEnd
我在脚本末尾创建了一个部分,它应该显示我的服务状态,但在执行后没有显示消息框。 可能是什么原因?
Section "Create Service"
ExecShellWait '' 'sc.exe' 'create myservice error= "severe" displayname= "myservice" type= "own" start= "auto" binpath= "$INSTDIR\MyService.exe"' SW_HIDE
SectionEnd
Section "Start Service"
ExecShellWait '' 'sc.exe' 'start myservice' SW_HIDE
SectionEnd
Section "Ensure Running"
StrCpy $R0 '"$SYSDIR\cmd.exe" /c "sc QUERY myservice | FIND /C "RUNNING""'
nsExec::ExecToStack '$R0'
Pop $R1 # contains return code
Pop $R2 # contains output
${If} $R1 == "0"
DetailPrint "checking if command is success"
${If} $R2 == "1"
MessageBox mb_ok "myservice is Running" # it's running
${Else}
MessageBox mb_ok "Not Running" # it's not running
${EndIf}
${Else}
DetailPrint "command failed"
${EndIf}
SectionEnd ```
nsExec::ExecToStack /OEM '$R0' didn't change anything. During installation it rushes to finish page after sc exec ..Do I need to add additional page page here ?
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ..\license.rtf
; Page custom pageRegistration
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
没有看到输出,我只能猜测存在某种 Unicode 问题。
将 nsExec::ExecToStack '$R0'
更改为 nsExec::ExecToStack /OEM '$R0'
。
也就是说,我不知道 运行 字符串是否总是英文的。您可以使用 NSIS wiki 上的几个服务插件和宏。
或者你可以使用这个:
!include "LogicLib.nsh"
!include "Win\COM.nsh"
!include "Win\Propkey.nsh"
Function IsServiceRunning
Exch [=10=]
Push
StrCpy [=10=]
!insertmacro ComHlpr_CreateInProcInstance {13709620-C279-11ce-A49E-444553540000} {A4C6892C-3BA9-11D2-9DEA-00C04FB16162} r0 "" ; IE5+?
${If} [=10=] P<> 0
System::Call "[=10=]->36(wr1,@r1)i.s"
${IUnknown::Release} [=10=] ""
Pop [=10=]
${If} [=10=] >= 0
StrCpy [=10=] 0
Push
${V_GetVT} r2
${V_GetBOOL} r1
${If} = ${VT_BOOL}
${AndIf} <> ${VARIANT_FALSE}
StrCpy [=10=] 1
${EndIf}
Pop
${Else}
StrCpy [=10=] 0
${EndIf}
${EndIf}
Pop
Exch [=10=]
FunctionEnd
Section "Example"
Push "RemoteRegistry"
Call IsServiceRunning
Pop [=10=]
DetailPrint "RemoteRegistry running=[=10=]"
Push "Themes"
Call IsServiceRunning
Pop [=10=]
DetailPrint "Themes running=[=10=]"
SectionEnd