'NSIS script doesn't display service status

I created section at the end of script which suppose to display myservice status, but no messagebox displays after exec. What might be the reason?

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source