Announcement

Collapse
No announcement yet.

NSIS Simple Service Plugin

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NSIS Simple Service Plugin

    Hi,

    I´ve create a service plugin. This plugin contains basic service functions like start, stop the service or checking the service status. It also contains advanced service functions for example setting the service description, changed the logon account, granting or removing the service logon privilege.

    Here the function list:

    SimpleSC::Install [name_of_service] [display_name] [start_type] [service_commandline] [dependencies] [account] [password]
    SimpleSC::Remove [name_of_service]
    SimpleSC::StartService [name_of_service]
    SimpleSC::StopService [name_of_service]
    SimpleSC::PauseService [name_of_service]
    SimpleSC::ContinueService [name_of_service]
    SimpleSC::RestartService [name_of_service]
    SimpleSC::ExistsService [name_of_service]
    SimpleSC::GetServiceDisplayName [name_of_service]
    SimpleSC::GetServiceName [display_name]
    SimpleSC::GetServiceStatus [name_of_service]
    SimpleSC::SetServiceDescription [name_of_service] [service_description]
    SimpleSC::SetServiceStartType [name_of_service] [start_type]
    SimpleSC::SetServiceLogon [name_of_service] [account] [password]
    SimpleSC::GrantServiceLogonPrivilege [account]
    SimpleSC::RemoveServiceLogonPrivilege [account]
    SimpleSC::ServiceIsPaused [name_of_service]
    SimpleSC::ServiceIsRunning [name_of_service]
    SimpleSC::ServiceIsStopped [name_of_service]
    Here is the link to the wiki: http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin

    Any comments, suggestions and questions are welcome...

    Best regards

    Rainer

  • #2
    Hi,

    I just tested your plugin and was surprised to see that it doesn't need admin privileges to check the status of a service, contrary to the other available plugins. This was tested on Vista and XP Pro SP2.

    This is very useful to me and I would like to know if this behaviour is intended and maybe a little explanation too

    These are the scripts I used to double-check :

    code:
    Name "simpleservice-test"
    Outfile "simpleservice-test.exe"
    ShowInstDetails show
    RequestExecutionLevel user

    Section -Main SEC0000
    SetAutoClose false
    SimpleSC::GetServiceStatus "W32Time"
    pop $0
    pop $1
    DetailPrint $0
    DetailPrint $1
    SectionEnd

    code:
    Name "nsscm-test"
    Outfile "nsscm-test.exe"
    ShowInstDetails show
    RequestExecutionLevel user

    Section -Main SEC0000
    SetAutoClose false
    nsSCM::QueryStatus "W32Time"
    Pop $0
    Pop $1
    DetailPrint $0
    DetailPrint $1
    SectionEnd

    code:
    !include "servicelib.nsh"

    Name "servicelib-test"
    Outfile "servicelib-test.exe"
    ShowInstDetails show
    RequestExecutionLevel user

    Section -Main SEC0000
    SetAutoClose false
    !insertmacro SERVICE "status" "W32Time" ""
    pop $0
    DetailPrint $0
    SectionEnd

    And these are the results :

    * simpleservice-test:
    0
    4

    * nsscm-test:
    error
    1

    * servicelib-test:
    false
    Thanks for the great job !

    Comment


    • #3
      I found out so far that :

      - GetServiceStatus works with admin and user privileges
      - ExistsService only works with admin privileges
      - ServiceIsRunning works with both privileges, but documentation on the wiki is wrong : '1' means the service is running

      This has been tested on Vista and XP.

      Comment


      • #4
        Hi,

        Originally posted by Nicolas Cuny
        I found out so far that :

        - ExistsService only works with admin privileges
        - ServiceIsRunning works with both privileges, but documentation on the wiki is wrong : '1' means the service is running

        This has been tested on Vista and XP.
        I´ve changed the access flags for each functions so every function will be executed with the lowest privilege which is necessary. So I think ExistsService should now work with user privileges. A new version (1.01) of this plugin is available now.

        I´ve changed the wrong Result-Description for the functions ServiceIsRunning, ServiceIsPaused and ServiceIsStopped.

        Any comments, suggestions and questions are welcome...

        Best regards

        Rainer

        Comment


        • #5
          Hello,

          I'm am currently building an installer for a service application and I am using this plugin to create the service itself.

          I am able to create the service but in the service control manager there is no description. Also when the service starts a message is logged in the even viewer and then it says Service1 has been started even tho my service is called something else.
          Most likely im doing something wrong, it would be nice if someone could point me in the right direction.

          I have used the following command to add the service:
          SimpleSC::InstallService "MyService" "My Service" "2" "$INSTDIR\bin\MyService.exe" "" "" ""

          Thanks in advance for any help with this!

          // Mika

          Comment


          • #6
            Hi,

            I am able to create the service but in the service control manager there is no description.
            Thats correct. If you install the service the service description is not set. Please use the function "SetServiceDescription" to set a seperate description.

            Also when the service starts a message is logged in the even viewer and then it says Service1 has been started even tho my service is called something else.
            I think Service1 is your Display name, otherwise you can´t see it in eventlog. But I think your Key-Name (It is called [name_of_service] in plugin doc) is always the same. Don´t confuse Display-Name and Key-Name.

            The Display-Name is a unique name you can see in the service controller at the column "Name".

            The Key-Name is a unique name you can see if you show the properties of a service.

            Best regards

            Rainer

            Comment


            • #7
              Thank you so much for your response.

              The SetServiceDescription function works like a charm!
              I found out that the Service1 issue is a programming issue and it has nothing to do with this plugin.

              Thank you for the fast response and for this plugin!

              Comment


              • #8
                I tried to use your dll.
                I copied it into the Plugins folder in the folder where NSIS is installed, but the compiler always says that "SimpleSC::Install" is an illegal command.

                Do I need to define somewhere in my NSIS Script that I want to use your dll? I was not able to find anything about this in the Wiki, this forum or with google.
                Perhaps I'm blind

                Thank you for your help!

                Comment


                • #9
                  Hello Andy,

                  Originally posted by Andy1988
                  I tried to use your dll.
                  I copied it into the Plugins folder in the folder where NSIS is installed, but the compiler always says that "SimpleSC::Install" is an illegal command.

                  Do I need to define somewhere in my NSIS Script that I want to use your dll? I was not able to find anything about this in the Wiki, this forum or with google.
                  Perhaps I'm blind
                  A good message to you: You are not blind . That was my mistake. The documentation (in the readme.txt and on the wiki) was wrong about the name of the install and remove function. Only in the example it was correct. The function names are:
                  • SimpleSC::InstallService
                    SimpleSC::RemoveService


                  I´ve fixed it in the file and on the wiki.

                  Best regards

                  Rainer

                  Comment


                  • #10
                    Originally posted by Speed78
                    Hello Andy,



                    A good message to you: You are not blind . That was my mistake. The documentation (in the readme.txt and on the wiki) was wrong about the name of the install and remove function. Only in the example it was correct. The function names are:
                    • SimpleSC::InstallService
                      SimpleSC::RemoveService


                    I´ve fixed it in the file and on the wiki.

                    Best regards

                    Rainer
                    It's great to hear that there is nothing wrong with my eyes
                    Now everything works like expected!

                    BTW: Great plugin! And thank you for your work and fast help!

                    Comment


                    • #11
                      Request

                      I think this is the best service plugin so far.

                      I do have one request. An option that will show the config info.
                      Like the qc option does for SC.exe in windows
                      qc--------------Queries the configuration information for a service.

                      The option I am looking for the most is to read BINARY_PATH_NAME

                      Thanks again for the great plugin
                      Chris

                      Comment


                      • #12
                        Hello Chris,

                        I will add a function like "GetServicePath" in the next release. I think I will release it next days.

                        Best regards

                        Rainer

                        Comment


                        • #13
                          When I do a SimpleSC::RemoveService yet the service is still in the Services list. If I try to restart the service I get a "The specified service has been marked for deletion."

                          The service is removed from the list upon the next reboot.

                          The only reason I ask is I'd like to let the user uninstall/reinstall without rebooting.

                          I believe the "sc delete" command removes the service without a reboot.

                          Does your plugin use "sc" or some other command?

                          Thanks in advance,

                          Matt

                          Comment


                          • #14
                            Hi lushdog,

                            Originally posted by lushdog
                            When I do a SimpleSC::RemoveService yet the service is still in the Services list. If I try to restart the service I get a "The specified service has been marked for deletion."

                            The service is removed from the list upon the next reboot.

                            The only reason I ask is I'd like to let the user uninstall/reinstall without rebooting.

                            I believe the "sc delete" command removes the service without a reboot.

                            Does your plugin use "sc" or some other command?

                            Thanks in advance,

                            Matt
                            The plugin uses the windows api functions. I think you have removed the service during your service list windows was opened!? If the service list is opened this is a default behaviour. Try to close the service list window and remove the service and then open the service list. You will see that the service is removed.

                            "sc" uses the same functions like my plugin so "sc" has the same behaviour.

                            Please remember: You should stop the service before you removing it.

                            Best Regards

                            Rainer

                            Comment


                            • #15
                              New Version 1.03

                              Hi,

                              I´ve released a new version of the NSIS Simple Service Plugin. The new version provides the function "SimpleSC::GetServiceBinaryPath" to get the binary path of a specified service.

                              You can find more informations and download file on the wiki page (http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin).

                              If you have any questions please let me now.

                              Best regards

                              Rainer

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎