Talk:NSIS Simple Service Plugin: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This is a great plugin. Almost perfect for our needs, but missing some features. For example, I cannot set the load order group when creating a service. Very rare, but a required for me. Sorta wished the code was written with something more common than Pascal so I could code it in.
-----
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>

Latest revision as of 15:03, 31 May 2010

This is a great plugin. Almost perfect for our needs, but missing some features. For example, I cannot set the load order group when creating a service. Very rare, but a required for me. Sorta wished the code was written with something more common than Pascal so I could code it in.



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