Talk:NSIS Simple Service Plugin: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
(Added code example.)
Line 1: Line 1:
Changing the return value of ExistsService really caught me off guard!  I thought 1.21 was broken until I looked at the changelog :)  If anyone else is here because of a similar problem, ExistsService now returns 0 on success, and non-zero otherwise.
Changing the return value of ExistsService really caught me off guard!  I thought 1.21 was broken until I looked at the changelog :)  If anyone else is here because of a similar problem, ExistsService now returns 0 on success, and non-zero otherwise.
----
This is a great plugin. Much better than Servicelib.nsh.
Code example:
<pre>
# Installer sections
Section -Main SEC0000
    ...
    ; Install the service using NSIS Simple Service Plugin
    SimpleSC::InstallService "$(^Name)" "Chromodoris" "16" "2" "$INSTDIR\Chromodoris.exe" "" "NT AUTHORITY\NetworkService" ""
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) installation failed: could not create service."
    Abort
   
    SimpleSC::SetServiceDescription "$(^Name)" "UCNetworks' Chromodoris 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 "$(^Name)" ""
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) installation failed: could not start service."
    Abort
       
SectionEnd
# Uninstaller sections
Section /o -un.Main UNSEC0000
    ; Stop the service using NSIS Simple Service Plugin
    SimpleSC::ExistsService "$(^Name)"
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +1 NoServiceExists
   
    ; Stop the service using NSIS Simple Service Plugin
    SimpleSC::StopService "$(^Name)"
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) uninstallation failed: could not stop service."
    Abort
   
    ; Stop the service using NSIS Simple Service Plugin
    SimpleSC::RemoveService "$(^Name)"
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) uninstallation failed: could not remove service."
    Abort
   
NoServiceExists:
 
    ...
SectionEnd
</pre>

Revision as of 09:56, 20 July 2009

Changing the return value of ExistsService really caught me off guard! I thought 1.21 was broken until I looked at the changelog :) If anyone else is here because of a similar problem, ExistsService now returns 0 on success, and non-zero otherwise.



This is a great plugin. Much better than Servicelib.nsh.

Code example:

# Installer sections
Section -Main SEC0000

    ...

    ; Install the service using NSIS Simple Service Plugin 
    SimpleSC::InstallService "$(^Name)" "Chromodoris" "16" "2" "$INSTDIR\Chromodoris.exe" "" "NT AUTHORITY\NetworkService" ""
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) installation failed: could not create service."
    Abort
    
    SimpleSC::SetServiceDescription "$(^Name)" "UCNetworks' Chromodoris 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 "$(^Name)" ""
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) installation failed: could not start service."
    Abort
        
SectionEnd

# Uninstaller sections
Section /o -un.Main UNSEC0000

    ; Stop the service using NSIS Simple Service Plugin 
    SimpleSC::ExistsService "$(^Name)"
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +1 NoServiceExists
    
    ; Stop the service using NSIS Simple Service Plugin 
    SimpleSC::StopService "$(^Name)"
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) uninstallation failed: could not stop service."
    Abort
    
    ; Stop the service using NSIS Simple Service Plugin 
    SimpleSC::RemoveService "$(^Name)"
    Pop $0 ; returns an errorcode (<>0) otherwise success (0)
    IntCmp $0 0 +3
    MessageBox MB_OK|MB_ICONSTOP "$(^Name) uninstallation failed: could not remove service."
    Abort
    
NoServiceExists:
   
    ...

SectionEnd