Skip to content
⌘ NSIS Forum Archive

using nsis i need to start a disabled service

4 posts

shekara#

using nsis i need to start a disabled service

using I am try to start a service which is in disabled state and not started.
I am using simple SC plugin to achieve this. if the service is not disabled, I can start it.
but when it is disabled , it fails.

i have tried using SimpleSC::SetServiceStartType "service name" "2". but it has failed
shekara#
when the service is set to manual or disabled, i am having issues. if it is set to automatic, it works
shekara#
!define ServiceStop `!insertmacro ServiceStop`
!macro ServiceStop SVC stopTime StopSer
Push $0
Push $1
Push ${StopSer}
SimpleSC::ExistsService "${SVC}"
Pop $0
${If} $0 == 0
MessageBox MB_OK "${SVC} exists $0"
SimpleSC::GetServiceStartType "${SVC}"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns the start type of the service
MessageBox MB_OK "${SVC} start type $1. 4 is disabled, 2 is autostart"
${If} $1 == 4
${OrIf} $1 != 2
${OrIf} $1 != 3
#SimpleSC::SetServiceStartType [name_of_service] [start_type]
SimpleSC::SetServiceStartType "${SVC}" "2"
Pop $0 ;returns an errorcode (<>0) otherwise success (0)
MessageBox MB_OK "${SVC} SetServiceStartType $0"

SimpleSC::GetServiceDelayedAutoStartInfo "${SVC}"
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns the delayed auto-start configuration
MessageBox MB_OK "${SVC} GetServiceDelayedAutoStartInfo $1"
${If} $1 == 1
SimpleSC::SetServiceDelayedAutoStartInfo "${SVC}" "1"
${EndIf}
${Endif}

SimpleSC::GetServiceStatus "${SVC}"
Pop $0
Pop $1
${If} $1 != 1
${OrIf} $1 = 4
MessageBox MB_OK "${SVC} service status is $1"
SimpleSC::StopService "${SVC}" ""
Pop $0
Pop $1

MessageBox MB_OK " stop service type value is 0 is $0 is $1"
Exch $0
Pop ${StopSer}
MessageBox MB_OK " Exch value is $0 amd StopSer is ${StopSer}"
${Endif}
${Else}
Return
${Endif}
Pop $1
Exch $0
!macroend

!insertmacro ServiceStop "GoogleChromeElevationService" 30 $0
Pop $0
MessageBox MB_OK "$0"
${If} $0 != 0
MessageBox MB_OK "ERROR = Unable to stop GoogleChromeElevationService Service"
Abort
${Else}
MessageBox MB_OK "GoogleChromeElevationService service stop successfully"
${EndIf}