有关SimpleSC插件的实例

!include MUI2.nsh
!include LogicLib.nsh
!include nsDialogs.nsh
Name "NetHalt"
OutFile "nhclient.exe"
InstallDir $PROGRAMFILESNetHalt
InstallDirRegKey HKLM "SOFTWARENetHalt" "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 "SOFTWARENetHalt" "InstallDir" $INSTDIR
 cinst::reg_write "dword" "SOFTWARENetHalt" "use_server" "0"
 cinst::reg_write "string" "SOFTWARENetHalt" "server_name" ""
 cinst::reg_write "dword" "SOFTWARENetHalt" "server_port" "0"
 cinst::reg_write "dword" "SOFTWARENetHalt" "server_refresh" "1800"
 cinst::reg_write "dword" "SOFTWARENetHalt" "warning" "300"
 cinst::reg_write "dword" "SOFTWARENetHalt" "abort" "0"
 cinst::reg_write "dword" "SOFTWARENetHalt" "delay" "0"
 cinst::reg_write "string" "SOFTWARENetHalt" "sdtimes" ""
 WriteUninstaller "$INSTDIRuninstall.exe"
 File "srcnhclient.exe"
 File "srcevlog.dll"
 File "srcnhtray.exe"
 File "srcnhconfig.exe"
 # Add the event log source (evlog.dll) to the registry
 #
 WriteRegStr HKLM "SYSTEMCurrentControlSetServicesEventlogApplicationNetHalt Client" "EventMessageFile" "$INSTDIRevlog.dll"
 WriteRegDWORD HKLM "SYSTEMCurrentControlSetServicesEventlogApplicationNetHalt Client" "TypesSupported" 0x00000007
 # Add the uninstaller to Add/Remove programs
 #
 WriteRegStr HKLM "SOFTWAREMicrosoftWindowsCurrentVersionUninstallNetHalt" "DisplayName" "NetHalt"
 WriteRegStr HKLM "SOFTWAREMicrosoftWindowsCurrentVersionUninstallNetHalt" "UninstallString" "$INSTDIRuninstall.exe"
 WriteRegDWORD HKLM "SOFTWAREMicrosoftWindowsCurrentVersionUninstallNetHalt" "NoModify" 1
 WriteRegDWORD HKLM "SOFTWAREMicrosoftWindowsCurrentVersionUninstallNetHalt" "NoRepair" 1
 # Install and start the NetHalt service
 # TODO: Check for errors
 #
 DetailPrint "Installing NetHalt Client service..."
 SimpleSC::InstallService "nhclient" "NetHalt Client" "16" "2" "$INSTDIRnhclient.exe" "" "" ""
 DetailPrint "Starting NetHalt Client service..."
 SimpleSC::StartService "nhclient"
 # Add nhtray.exe to the registry to run at login
 #
 WriteRegStr HKLM "SOFTWAREMicrosoftWindowsCurrentVersionRun" "NetHalt" "$INSTDIRnhtray.exe"
 # Launch nhtray.exe
 #
 Exec '"$INSTDIRnhtray.exe"'
 # Create shortcuts
 #
 CreateDirectory "$SMPROGRAMSNetHalt"
 CreateShortCut "$SMPROGRAMSNetHaltTray Icon.lnk" "$INSTDIRnhtray.exe"
 CreateShortCut "$SMPROGRAMSNetHaltConfiguration.lnk" "$INSTDIRnhconfig.exe"
 CreateShortCut "$SMPROGRAMSNetHaltUninstall.lnk" "$INSTDIRuninstall.exe"
SectionEnd
Function un.onInit
 SetShellVarContext all
 ReadRegStr $INSTDIR HKLM "SOFTWARENetHalt" "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 "$SMPROGRAMSNetHaltTray Icon.lnk"
 Delete "$SMPROGRAMSNetHaltConfiguration.lnk"
 Delete "$SMPROGRAMSNetHaltUn-Install.lnk"
 Delete "$SMPROGRAMSNetHalt"
 DeleteRegValue HKLM "SOFTWAREMicrosoftWindowsCurrentVersionRun" "NetHalt"
 DeleteRegKey HKLM "SYSTEMCurrentControlSetServicesEventlogApplicationNetHalt Client"
 DeleteRegKey HKLM "SOFTWAREMicrosoftWindowsCurrentVersionUninstallNetHalt"
 Delete "$INSTDIRnhclient.exe"
 Delete "$INSTDIRevlog.dll"
 Delete "$INSTDIRnhtray.exe"
 Delete "$INSTDIRuninstall.exe"
 RMDir $INSTDIR
SectionEnd
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容