Archive: Install as a System Service


I would like to add an option to install an executable as a system service. I am quite sure this would be done through the registry but I am not sure where this is done.

I would also like the option to appear only if the user is running Windows NT. Is it possible to hide sections based on string values? I have not been able to get this to work.


I just had a quick look at my registry and the path for the WinNT/W2K system services is:
HKLM, SYSTEM\Services

A good example of a W2K System Service which uses it's own executable is e.g. Telnet (TlntSvr).
Have a look at the structure and you should be able to put up a new service with NSIS.

For more information about Winows System Services goto:
http://msdn.microsoft.com/library/
and search for system services.

I'm not sure what you mean by "hide sections based on string values". If you mean that you would like to create a section which does not show up in the install-options just create a Section called "".

If you need to detect the Windows Version of a system I recommend the following address:

http://www.firehose.net/free/nsis/functions.html

Good luck!;)


Unfortunately, section hiding/disabling is done at compile time and not runtime. So you can't have certain sections be only for Win9x or WinNT.


So you want to have s.th. like Section "Install as System Service" which does only appear when the user's OS is NT or W2K or whatever...

Perhaps this will work:

Section .onInit
Call GetWindowsVersion

StrCmp $0 'NT' 2 lbl_doIT ''
StrCmp $0 '2000' lbl_doIT ''

;The $0 Value will be assigned by the
;GetWindowsVersion from
;http://www.firehose.net/free/nsis/functions.html#GetWindows
;Version

StrCpy $1 ""
Goto lbl_end

lbl_doIT:
StrCpy $1 'Install as System Service'

lbl_end:

SectionEnd


Section $1
StrCmp $1 'Install as System Service' '' lbl_skip

BLABLA...

lbl_skip:
SectionEnd

Could this work? Depends on if NSIS first collects all the Sections (then $1 will be unassigned and the section won't install even if your OS is NT/W2K) or if it does Section .oninit before that (which then should work).

I'm not quite sure. Just give it a try!

P.S.:
Otherwise you'll just have to allow every-OS-user to select this Section (Install as System Service) for installation and before all the stuff in the section make a GetWindowsVersion detect and if the OS is not NT/W2K just skip the Section with an explanation, like MessageBox MB_OK "Only Windows NT/2000 users can install a system service"


Sections are created at compile-time, unfortunately, and variables and functions are assigned at runtime. So the only way to do it is to have the section be visible all the time, and simply have it do nothing if the target computer isn't NT.