# NetHalt - Server install script # Copyright (C) 2008 Daniel Collins # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # * Neither the name of the author nor the names of its contributors may # be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. !include MUI2.nsh !include LogicLib.nsh !include nsDialogs.nsh Name "NetHalt Server" OutFile "nhserver.exe" InstallDir "$PROGRAMFILES\NetHalt Server" InstallDirRegKey HKLM "SOFTWARE\NetHalt Server" "InstallDir" !define MUI_ABORTWARNING !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "COPYING" !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_LANGUAGE "English" Function .onInit nsisos::osversion ${If} $0 < 5 MessageBox MB_OK "Windows 2000 (NT 5.0) or greater is required" Abort ${EndIf} FunctionEnd Section "NetHalt Server" SetShellVarContext all SetOutPath $INSTDIR # Check if the NetHalt service is installed # SimpleSC::ExistsService "nhserver" Pop $0 # Stop+Remove the NetHalt service if it's installed # ${If} $0 == 0 DetailPrint "Stopping NetHalt Server service..." SimpleSC::StopService "nhserver" DetailPrint "Removing NetHalt Server service..." SimpleSC::RemoveService "nhserver" ${EndIf} WriteRegStr HKLM "SOFTWARE\NetHalt Server" "InstallDir" $INSTDIR cinst::reg_write "string" "SOFTWARE\NetHalt Server" "bind_addr" "0.0.0.0" cinst::reg_write "dword" "SOFTWARE\NetHalt Server" "bind_port" "24875" cinst::reg_write "dword" "SOFTWARE\NetHalt Server" "client_timeout" "30" WriteUninstaller "$INSTDIR\uninstall.exe" File "src\nhserver.exe" File "src\evlog.dll" SetOverwrite off File "nethalt.ini" # Add the event log source (evlog.dll) to the registry # WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Server" "EventMessageFile" "$INSTDIR\evlog.dll" WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Server" "TypesSupported" 0x00000007 # Add the uninstaller to Add/Remove programs # WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt Server" "DisplayName" "NetHalt Server" WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt Server" "UninstallString" "$INSTDIR\uninstall.exe" WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt Server" "NoModify" 1 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt Server" "NoRepair" 1 # Install and start the NetHalt service # TODO: Check for errors # DetailPrint "Installing NetHalt Server service..." SimpleSC::InstallService "nhserver" "NetHalt Server" "16" "2" "$INSTDIR\nhserver.exe" "" "NT AUTHORITY\LocalService" "" DetailPrint "Starting NetHalt Server service..." SimpleSC::StartService "nhserver" # Create shortcuts # CreateDirectory "$SMPROGRAMS\NetHalt Server" CreateShortCut "$SMPROGRAMS\NetHalt Server\Edit nethalt.ini.lnk" "$INSTDIR\nethalt.ini" CreateShortCut "$SMPROGRAMS\NetHalt Server\Uninstall.lnk" "$INSTDIR\uninstall.exe" SectionEnd Function un.onInit SetShellVarContext all ReadRegStr $INSTDIR HKLM "SOFTWARE\NetHalt Server" "InstallDir" MessageBox MB_YESNO "This will uninstall the NetHalt Server, continue?" IDYES NoAbort Abort NoAbort: FunctionEnd Section "Uninstall" # Stop+Remove the NetHalt service # DetailPrint "Stopping NetHalt Server service..." SimpleSC::StopService "nhserver" DetailPrint "Removing NetHalt Server service..." SimpleSC::RemoveService "nhserver" # Delete shortcuts # Delete "$SMPROGRAMS\NetHalt Server\Edit nethalt.ini.lnk" Delete "$SMPROGRAMS\NetHalt Server\Uninstall.lnk" RMDir "$SMPROGRAMS\NetHalt Server" DeleteRegKey HKLM "SOFTWARE\NetHalt Server" DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Server" DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt Server" Delete "$INSTDIR\nhserver.exe" Delete "$INSTDIR\evlog.dll" Delete "$INSTDIR\uninstall.exe" RMDir $INSTDIR SectionEnd