zoukankan      html  css  js  c++  java
  • 无比经典的nsis带SimpleSC脚本

    高手进阶…………

    因为需要用到SimpleSC::InstallService这个功能,故此搜索到此篇,看来大有收获,转帖在此




    # NetHalt - NSIS installer script
    # Copyright (C) 2008 Daniel Collins <solemnwarning@solemnwarning.net>
    # 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"
    OutFile "nhclient.exe"

    InstallDir $PROGRAMFILES\NetHalt
    InstallDirRegKey HKLM "SOFTWARE\NetHalt" "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

    # Do local install
    #
    Section "NetHalt"
        SetShellVarContext all
        SetOutPath $INSTDIR
        
        # Stop all running nhtray.exe processes
        #
        StrCpy $0 "nhtray.exe"
        KillProc::KillProcesses
        
        # Check if the NetHalt service is installed
        #
        SimpleSC::ExistsService "nhclient"
        Pop $0
        
        # Stop+Remove the NetHalt service if it's installed
        #
        ${If} $0 == 0
            DetailPrint "Stopping NetHalt Client service..."
            SimpleSC::StopService "nhclient"
            
            DetailPrint "Removing NetHalt Client service..."
            SimpleSC::RemoveService "nhclient"
        ${EndIf}
        
        WriteRegStr HKLM "SOFTWARE\NetHalt" "InstallDir" $INSTDIR
        
        cinst::reg_write "dword" "SOFTWARE\NetHalt" "use_server" "0"
        cinst::reg_write "string" "SOFTWARE\NetHalt" "server_name" ""
        cinst::reg_write "dword" "SOFTWARE\NetHalt" "server_port" "0"
        cinst::reg_write "dword" "SOFTWARE\NetHalt" "server_refresh" "1800"
        
        cinst::reg_write "dword" "SOFTWARE\NetHalt" "warning" "300"
        cinst::reg_write "dword" "SOFTWARE\NetHalt" "abort" "0"
        cinst::reg_write "dword" "SOFTWARE\NetHalt" "delay" "0"
        cinst::reg_write "string" "SOFTWARE\NetHalt" "sdtimes" ""
        
        WriteUninstaller "$INSTDIR\uninstall.exe"
        
        File "src\nhclient.exe"
        File "src\evlog.dll"
        File "src\nhtray.exe"
        File "src\nhconfig.exe"
        
        # Add the event log source (evlog.dll) to the registry
        #
        WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client" "EventMessageFile" "$INSTDIR\evlog.dll"
        WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client" "TypesSupported" 0x00000007
        
        # Add the uninstaller to Add/Remove programs
        #
        WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "DisplayName" "NetHalt"
        WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "UninstallString" "$INSTDIR\uninstall.exe"
        WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "NoModify" 1
        WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt" "NoRepair" 1
        
        # Install and start the NetHalt service
        # TODO: Check for errors
        #
        DetailPrint "Installing NetHalt Client service..."
        SimpleSC::InstallService "nhclient" "NetHalt Client" "16" "2" "$INSTDIR\nhclient.exe" "" "" ""
        
        DetailPrint "Starting NetHalt Client service..."
        SimpleSC::StartService "nhclient"
        
        # Add nhtray.exe to the registry to run at login
        #
        WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "NetHalt" "$INSTDIR\nhtray.exe"
        
        # Launch nhtray.exe
        #
        Exec '"$INSTDIR\nhtray.exe"'
        
        # Create shortcuts
        #
        CreateDirectory "$SMPROGRAMS\NetHalt"
        CreateShortCut "$SMPROGRAMS\NetHalt\Tray Icon.lnk" "$INSTDIR\nhtray.exe"
        CreateShortCut "$SMPROGRAMS\NetHalt\Configuration.lnk" "$INSTDIR\nhconfig.exe"
        CreateShortCut "$SMPROGRAMS\NetHalt\Uninstall.lnk" "$INSTDIR\uninstall.exe"
    SectionEnd

    Function un.onInit
        SetShellVarContext all
        ReadRegStr $INSTDIR HKLM "SOFTWARE\NetHalt" "InstallDir"
        
        MessageBox MB_YESNO "This will uninstall NetHalt, continue?" IDYES NoAbort
        Abort
        NoAbort:
    FunctionEnd

    Section "Uninstall"
        # Stop and remove the NetHalt service
        #
        DetailPrint "Stopping NetHalt Client service..."
        SimpleSC::StopService "nhclient"
        
        DetailPrint "Removing NetHalt Client service..."
        SimpleSC::RemoveService "nhclient"
        
        # Stop all running nhtray.exe processes
        #
        StrCpy $0 "nhtray.exe"
        KillProc::KillProcesses
        
        # Delete shortcuts
        #
        Delete "$SMPROGRAMS\NetHalt\Tray Icon.lnk"
        Delete "$SMPROGRAMS\NetHalt\Configuration.lnk"
        Delete "$SMPROGRAMS\NetHalt\Un-Install.lnk"
        Delete "$SMPROGRAMS\NetHalt"
        
        DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "NetHalt"
        DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Eventlog\Application\NetHalt Client"
        DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NetHalt"
        
        Delete "$INSTDIR\nhclient.exe"
        Delete "$INSTDIR\evlog.dll"
        Delete "$INSTDIR\nhtray.exe"
        Delete "$INSTDIR\uninstall.exe"
        RMDir $INSTDIR
    SectionEnd

  • 相关阅读:
    Android应用开发学习笔记之事件处理
    [置顶] 炎炎夏日,给你一次极爽的开发体验!——统一开发环境功能升级优化,正式上线V2.0!
    POJ 3468 A Simple Problem with Integers (伸展树区间更新求和操作 , 模板)
    京东商城发现了一枚Bug
    iOS_40_核心动画
    SVN——库合并
    ORACLE 8i 遇到报错:ORA-01631: max # extents (505) reached in table
    HDU 5366:The mook jong 递推
    Linux平台下裸设备的绑定:
    CSP:使用CryptoAPI解码X509证书内容
  • 原文地址:https://www.cnblogs.com/mareymarey111/p/2290893.html
Copyright © 2011-2022 走看看