Skip to content
⌘ NSIS Forum Archive

NSIS Simple Service Plugin

142 posts

T.Slappy#
By default all plug-ins can be used in commercial installers.
If it is not strictly prohibited in plug-in readme then feel free to use it.
dixonich#
Hello! My problem. Services plug-in not work! Help please!Service does not start!

!define PRODUCT_NAME "MyApp"
!define PRODUCT_VERSION "19"
!define pkgdir "C:\Swe"

!include "MUI.nsh"
SetCompressor /SOLID lzma

!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "Russian"

Name "${PRODUCT_NAME}"
Caption "Установка ${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
ShowInstDetails show

Section
SetOutPath "C:\"

File "${pkgdir}\SystemTrayDemo.exe"

SimpleSC::InstallService "ServiceStartD" "Testing123D" "16" "2" "C:\SystemTrayDemo.exe" "" "" ""
SimpleSC::StartService "ServiceStartD" "" 30
SectionEnd
Speed78#
Originally Posted by dixonich View Post
Hello! My problem. Services plug-in not work! Help please!Service does not start!

!define PRODUCT_NAME "MyApp"
!define PRODUCT_VERSION "19"
!define pkgdir "C:\Swe"

!include "MUI.nsh"
SetCompressor /SOLID lzma

!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "Russian"

Name "${PRODUCT_NAME}"
Caption "Установка ${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe"
ShowInstDetails show

Section
SetOutPath "C:\"

File "${pkgdir}\SystemTrayDemo.exe"

SimpleSC::InstallService "ServiceStartD" "Testing123D" "16" "2" "C:\SystemTrayDemo.exe" "" "" ""
SimpleSC::StartService "ServiceStartD" "" 30
SectionEnd
Which error mesage do you got (GetErrorMessage)? Are you using the unicode version of NSIS?

Kind regards

Rainer
nuoyantaizi#
Hi,Speed78
Nice to meet you.I have a problem when use NSIS Simple Service Plugin to install a windows service named "Apache".
When i use "SimpleSC::InstallService ...." ,the service is installed ok,but it can not start,the error is "required components not installed".
I have a try to use "apache/bin/httpd -k install",i saw the dependences are "AFD",and "TCP/IP Protocal Driver / IPSEC driver".
So,how can i use simplesc to install this apache ?

By the way,StartSercie,StopService need 30 seconds,that's so long! My production need to install 4 service on user's computer,so that's need too much time! Can you tell me if the SimpleSC can do this like "sc start httpd","sc stop httpd" ?

Best Regards
From your chinese friend 🙂
jpderuiter#
When i use "SimpleSC::InstallService ...." ,the service is installed ok,but it can not start,the error is "required components not installed".
I have a try to use "apache/bin/httpd -k install",i saw the dependences are "AFD",and "TCP/IP Protocal Driver / IPSEC driver".
So,how can i use simplesc to install this apache ?
Use "AFD/IPSec/Tcpip" as dependencies in the InstallService command (see http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin)
nuoyantaizi#
Thank you very much

Originally Posted by jpderuiter View Post
Use "AFD/IPSec/Tcpip" as dependencies in the InstallService command (see http://nsis.sourceforge.net/NSIS_Simple_Service_Plugin)
To jpderuiter,
thank you very much!

I have a try what you said,the dependences are installed successfully! thanks again!
But tha apache software can not start yet.i don't know why,i think the software has its own process when use "-k install".but i still thanks you told me how to use the dependence parameter🙂

Another question,do you know how to install a .NET service except using "installutil.exe" ?
I have a .exe that developed by .net framework 4.0,i try to use SimpleSC to install ,and i failed,i must to use the .NET install tool "installutil.exe" to install it.

Ah,do you understand what i said ? 🙂 ,i am sorry about my english.

but,all of these are ok! i have write a .exe instead of that one.

Thanks again!

i have to improve my english now ,today i met a German teacher,thanks to God,there is a senior student there ,and she can speak german very well~🙂
Afrow UK#
You only need to use installutil.exe if the .NET service uses the ServiceInstaller/ServiceProcessInstaller classes to define its install configuration. If you just create the service and only extend the ServiceBase class then you can install it using the normal Windows APIs (i.e. SimpleSC will work).

Stu
aerDNA#
SimpleSC 1.30 crashes the installer when StartService, StopService etc. is used and Timeout parameter is omitted. Took me awhile to figure it out because I was recompiling an old script that worked fine with v1.29. So no big problem but it would be better if it just used the default timeout value instead of crashing.
dothebart#
GetServiceFailure / GetServiceFailureFlag returning 0?

I've been trying to add error handling to my installer; Service registering, adding a description, naming and starting works really well.

I'm producing a case where my service will abort its start, set dwWin32ExitCode to ERROR_SERVICE_SPECIFIC_ERROR, dwServiceSpecificExitCode to 1 and report that back. In that case the regular startup invocation via SimpleSC:


SimpleSC::StartService 'ARANGODB' '' 40
Pop $0
DetailPrint "Status: $0"
Will timeout, and then print out the statuscode 1053 others saw in this Forum too.

Revalidating with sc shows the popper SERVICE_EXIT_CODE 1 :

sc query "ArangoDB"

SERVICE_NAME: ArangoDB
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1066 (0x42a)
SERVICE_EXIT_CODE : 1 (0x1)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
However, trying to invoke these calls as cut'n'pasted from the wiki:

SimpleSC::ServiceIsRunning 'ARANGODB'
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns 1 (service is running) - returns 0 (service is not running)
DetailPrint "ServiceIsRunning 0: $0 1: $1 ${TRI_SVC_NAME}"

SimpleSC::GetServiceFailureFlag 'ARANGODB'
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns the service flag
DetailPrint "GetServiceFailureFlag 0: $0 1: $1"


SimpleSC::GetServiceFailure 'ARANGODB'
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns the reset period
Pop $2 ; returns the reboot message
Pop $3 ; returns the command
Pop $4 ; returns the first action (See "action_type_x" in the parameters)
Pop $5 ; returns the first action delay
Pop $6 ; returns the second action (See "action_type_x" in the parameters)
Pop $7 ; returns the second action delay
Pop $8 ; returns the third action (See "action_type_x" in the parameters)
Pop $9 ; returns the third action delay
DetailPrint "GetServiceFailure 0: $0 1: $1 2: $2 3: $3 4: $4 5: $5 6: $6 7: $7 8: $8 9: $9"
will only print 0's for all variables.

I've tried not setting the ServiceDescription, not setting the Friendly name, switching the all ASCII servicename from camelcase to uppercase, lowercase... No success...

I'm using NSIS 3.02 via cmake and VS 2015 to compile the service; The Host is a Windows Server 2016; the Installer asks for privileges, which seem to be enough to de/register start/stop the service. Any ideas what else I could try?
Anders#
1053 is ERROR_SERVICE_REQUEST_TIMEOUT "The service did not respond to the start or control request in a timely fashion"

There is no NSIS 3.02 yet, perhaps you just mean SVN trunk?

Works just fine for me
RequestExecutionLevel admin
Section
!macro TestSvcStuff SVCNAME
SimpleSC::ServiceIsRunning '${SVCNAME}'
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns 1 (service is running) - returns 0 (service is not running)
DetailPrint "ServiceIsRunning $$0=$0 $$1=$1 ${SVCNAME}"
SimpleSC::GetServiceFailureFlag '${SVCNAME}'
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns the service flag
DetailPrint "GetServiceFailureFlag 0: $0 1: $1"
SimpleSC::GetServiceFailure '${SVCNAME}'
Pop $0 ; returns an errorcode (<>0) otherwise success (0)
Pop $1 ; returns the reset period 
Pop $2 ; returns the reboot message
Pop $3 ; returns the command
Pop $4 ; returns the first action (See "action_type_x" in the parameters)
Pop $5 ; returns the first action delay 
Pop $6 ; returns the second action (See "action_type_x" in the parameters)
Pop $7 ; returns the second action delay 
Pop $8 ; returns the third action (See "action_type_x" in the parameters)
Pop $9 ; returns the third action delay 
DetailPrint "GetServiceFailure 0: $0 1: $1 2: $2 3: $3 4: $4 5: $5 6: $6 7: $7 8: $8 9: $9"
!macroend
!insertmacro TestSvcStuff "Fax" ; Not running
!insertmacro TestSvcStuff "Power" ; Running
SectionEnd 
Are you actually trying to get the WIN32_EXIT_CODE and SERVICE_EXIT_CODE values?
dothebart#
Oh, yes. updated from rc2 to .01 ;-)

Yes, I wanted to get the exit codes, so I could detect in the installer whether the service start was aborted by error.

I can actually see non-0 numbers on your power service example, and failures 1060 (similar to invoking sc) for services not installed on that system.

My stopped by startup abort service (as the sc output in the last post) does only give nulls.
Anders#
!define SVCNAME "Fax"
!include LogicLib.nsh
!define /ifndef SERVICE_QUERY_STATUS 4
System::Call 'ADVAPI32::OpenSCManager(p0, p0, i1)p.r1'
${If} $1 P<> 0
    System::Call 'ADVAPI32::OpenService(pr1, t"${SVCNAME}", i${SERVICE_QUERY_STATUS})p.r2'
    System::Call 'ADVAPI32::CloseServiceHandle(pr1)'
    ${If} $2 P<> 0
        System::Call 'ADVAPI32::QueryServiceStatus(pr2, @r3)i.r0' ; Note: NSIS 3+ syntax to "allocate" a SERVICE_STATUS
        ${If} $0 <> 0
            System::Call '*$3(i,i.r4,i,i.r5,i.r6)'
            DetailPrint "CurrentState=$4 Win32ExitCode=$5 ServiceSpecificExitCode=$6"
        ${EndIf}
        System::Call 'ADVAPI32::CloseServiceHandle(pr2)'
    ${EndIf}
${EndIf} 
There is a PayPal donation link on the SimpleSC wiki page so perhaps the author would be willing to add it for you...
Speed78#
SimpleSC Unicode Version released!

Dear all,

I know this thread is really pretty old but I'm happy to can say that I'm released the unicode version of the SimpleSC-Plugin so that NSIS 3.x is fully supported now. This plugin version has the same functions like the ANSI version. The ANSI version is still supported. You can find both versions here: https://nsis.sourceforge.io/NSIS_Simple_Service_Plugin

Thanks to Gabriel how triggered me to finish this port.

Best regards

Rainer
stopthemess#
Thank you for your work. The plugin works nicely, but it's very large (1mb). In fact, it's larger than my installed app! Can something be done about it? Thanks.

Perhaps you're bringing in UI code, which can be removed to reduce the file size.
See:


Also relevant pages I found:
To decrease executable size in FreePascal/Lazarus go to Project menu/Project Options and do the following in Compliation and Linking Check the following (Red Underlined) In Debuggin section of Comp…

Speed78#
Hi,

I know that the size is huge and there is no UI code in the DLL. If I create an empty DLL with Delphi 10.3 (RIO) (I'm not using Lazarus) the size is in "Release" mode 1 MB by default - in "Debug" around 5 MB.

I tried to remove the RTTI features which reduces the size to ~800KBs. I don't know if this is it worth - but I can do this with the next release.

Other options are:
- Use the ANSI DLL and a non Unicode Installer
- Use a better compressor in the NSIS setup to reduce the size of your installer
- Use UPX and compress the SimpleSC plugin (in my opinion the worst solution)
- Don't use the plugin and use Windows "net sh" or "sc" commands. (in my opinion the unprofessional solution)


The plugin is used only by the installer. Therefore I think a 1MB DLL is huge but in >= 2021 the size should no longer matter so much (it's only my opinion!)

Best regards

Rainer
stopthemess#
Thank you for the reply. So how's the ANSI DLL not so large?
Perhaps you can also try this:
How to create small EXE file (under 100KB)Project -> Options -> Runtime Packages Link with runtime packages: True Required external files: VCL Application: rtl260.bpl (12 MB), vcl260.bpl (4MB…

There are also tips here, perhaps something can be useful:

Speed78#
The ANSI file was compiled with Delphi 6. The unicode version was compiled with Delphi 10.3 (Rio).

I just tried your links but nothing of this really worked. When I add the Linker to use the runtime library I get in NSIS the same result as my last input parameter. If I set the PeFlags to 1 I get the same behaviour.

What seems to work is to remove RTTI. That reduce the size to 800KB. I think thats all what I can do.

Best regards

Rainer
stopthemess#
Hmmm, and what if you use Delphi 2009? Sorry for nagging, but as you said "using sc/net - the unprofessional solution", it feels to me that bringing a 1mb plugin is also an unprofessional solution.
Speed78#
Hey,

I think a 1MB plugin DLL with native NSIS support is a professional solution - 1MB is really not so huge - not 2021. The installer size is not so much greater if you select a good compressor. Therefore there should be no reason not using this DLL.

If you disagree - no problem... you can try it on your own. Buy and download Delphi 2009, use my code and try it. Feel free to change whatever you want - its open source 🙂.

Best regards

Rainer