杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1920|回复: 0

Nsis 带 SimpleSC 脚本

[复制链接]
发表于 2016-9-2 20:11:06 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. # NetHalt - NSIS installer script
  2. # Copyright (C) 2008 Daniel Collins <solemnwarning@solemnwarning.net>
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. #
  8. #    * Redistributions of source code must retain the above copyright
  9. #      notice, this list of conditions and the following disclaimer.
  10. #
  11. #    * Redistributions in binary form must reproduce the above copyright
  12. #      notice, this list of conditions and the following disclaimer in the
  13. #      documentation and/or other materials provided with the distribution.
  14. #
  15. #    * Neither the name of the author nor the names of its contributors may
  16. #      be used to endorse or promote products derived from this software
  17. #      without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
  20. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  23. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  29. !include MUI2.nsh
  30. !include LogicLib.nsh
  31. !include nsDialogs.nsh

  32. Name "NetHalt"
  33. OutFile "nhclient.exe"

  34. InstallDir $PROGRAMFILES\NetHalt
  35. InstallDirRegKey HKLM "SOFTWARE\NetHalt" "InstallDir"

  36. !define MUI_ABORTWARNING

  37. !insertmacro MUI_PAGE_WELCOME
  38. !insertmacro MUI_PAGE_LICENSE "COPYING"
  39. !insertmacro MUI_PAGE_DIRECTORY
  40. !insertmacro MUI_PAGE_INSTFILES

  41. !insertmacro MUI_LANGUAGE "English"

  42. Function .onInit
  43.     nsisos::osversion
  44.    
  45.     ${If} $0 < 5
  46.         MessageBox MB_OK "Windows 2000 (NT 5.0) or greater is required"
  47.         Abort
  48.     ${EndIf}
  49. FunctionEnd

  50. # Do local install
  51. #
  52. Section "NetHalt"
  53.     SetShellVarContext all
  54.     SetOutPath $INSTDIR
  55.    
  56.     # Stop all running nhtray.exe processes
  57.     #
  58.     StrCpy $0 "nhtray.exe"
  59.     KillProc::KillProcesses
  60.    
  61.     # Check if the NetHalt service is installed
  62.     #
  63.     SimpleSC::ExistsService "nhclient"
  64.     Pop $0
  65.    
  66.     # Stop+Remove the NetHalt service if it's installed
  67.     #
  68.     ${If} $0 == 0
  69.         DetailPrint "Stopping NetHalt Client service..."
  70.         SimpleSC::StopService "nhclient"
  71.         
  72.         DetailPrint "Removing NetHalt Client service..."
  73.         SimpleSC::RemoveService "nhclient"
  74.     ${EndIf}
  75.    
  76.     WriteRegStr HKLM "SOFTWARE\NetHalt" "InstallDir" $INSTDIR
  77.    
  78.     cinst::reg_write "dword" "SOFTWARE\NetHalt" "use_server" "0"
  79.     cinst::reg_write "string" "SOFTWARE\NetHalt" "server_name" ""
  80.     cinst::reg_write "dword" "SOFTWARE\NetHalt" "server_port" "0"
  81.     cinst::reg_write "dword" "SOFTWARE\NetHalt" "server_refresh" "1800"
  82.    
  83.     cinst::reg_write "dword" "SOFTWARE\NetHalt" "warning" "300"
  84.     cinst::reg_write "dword" "SOFTWARE\NetHalt" "abort" "0"
  85.     cinst::reg_write "dword" "SOFTWARE\NetHalt" "delay" "0"
  86.     cinst::reg_write "string" "SOFTWARE\NetHalt" "sdtimes" ""
  87.    
  88.     WriteUninstaller "$INSTDIR\uninstall.exe"
  89.    
  90.     File "src\nhclient.exe"
  91.     File "src\evlog.dll"
  92.     File "src\nhtray.exe"
  93.     File "src\nhconfig.exe"
  94.    
  95.     # Add the event log source (evlog.dll) to the registry
  96.     #
  97.     WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client" "EventMessageFile" "$INSTDIR\evlog.dll"
  98.     WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client" "TypesSupported" 0x00000007
  99.    
  100.     # Add the uninstaller to Add/Remove programs
  101.     #
  102.     WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "DisplayName" "NetHalt"
  103.     WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "UninstallString" "$INSTDIR\uninstall.exe"
  104.     WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "NoModify" 1
  105.     WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "NoRepair" 1
  106.    
  107.     # Install and start the NetHalt service
  108.     # TODO: Check for errors
  109.     #
  110.     DetailPrint "Installing NetHalt Client service..."
  111.     SimpleSC::InstallService "nhclient" "NetHalt Client" "16" "2" "$INSTDIR\nhclient.exe" "" "" ""
  112.    
  113.     DetailPrint "Starting NetHalt Client service..."
  114.     SimpleSC::StartService "nhclient"
  115.    
  116.     # Add nhtray.exe to the registry to run at login
  117.     #
  118.     WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "NetHalt" "$INSTDIR\nhtray.exe"
  119.    
  120.     # Launch nhtray.exe
  121.     #
  122.     Exec '"$INSTDIR\nhtray.exe"'
  123.    
  124.     # Create shortcuts
  125.     #
  126.     CreateDirectory "$SMPROGRAMS\NetHalt"
  127.     CreateShortCut "$SMPROGRAMS\NetHalt\Tray Icon.lnk" "$INSTDIR\nhtray.exe"
  128.     CreateShortCut "$SMPROGRAMS\NetHalt\Configuration.lnk" "$INSTDIR\nhconfig.exe"
  129.     CreateShortCut "$SMPROGRAMS\NetHalt\Uninstall.lnk" "$INSTDIR\uninstall.exe"
  130. SectionEnd

  131. Function un.onInit
  132.     SetShellVarContext all
  133.     ReadRegStr $INSTDIR HKLM "SOFTWARE\NetHalt" "InstallDir"
  134.    
  135.     MessageBox MB_YESNO "This will uninstall NetHalt, continue?" IDYES NoAbort
  136.     Abort
  137.     NoAbort:
  138. FunctionEnd

  139. Section "Uninstall"
  140.     # Stop and remove the NetHalt service
  141.     #
  142.     DetailPrint "Stopping NetHalt Client service..."
  143.     SimpleSC::StopService "nhclient"
  144.    
  145.     DetailPrint "Removing NetHalt Client service..."
  146.     SimpleSC::RemoveService "nhclient"
  147.    
  148.     # Stop all running nhtray.exe processes
  149.     #
  150.     StrCpy $0 "nhtray.exe"
  151.     KillProc::KillProcesses
  152.    
  153.     # Delete shortcuts
  154.     #
  155.     Delete "$SMPROGRAMS\NetHalt\Tray Icon.lnk"
  156.     Delete "$SMPROGRAMS\NetHalt\Configuration.lnk"
  157.     Delete "$SMPROGRAMS\NetHalt\Un-Install.lnk"
  158.     Delete "$SMPROGRAMS\NetHalt"
  159.    
  160.     DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "NetHalt"
  161.     DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client"
  162.     DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt"
  163.    
  164.     Delete "$INSTDIR\nhclient.exe"
  165.     Delete "$INSTDIR\evlog.dll"
  166.     Delete "$INSTDIR\nhtray.exe"
  167.     Delete "$INSTDIR\uninstall.exe"
  168.     RMDir $INSTDIR
  169. SectionEnd

复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 19:53 , Processed in 0.103173 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表