RestartManager.nsh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. !ifndef __WIN_RESTARTMANAGER__INC
  2. !define __WIN_RESTARTMANAGER__INC 1
  3. /**************************************************
  4. WinBase.h
  5. **************************************************/
  6. !define /IfNDef RESTART_MAX_CMD_LINE 1024
  7. !define /IfNDef RESTART_NO_CRASH 1
  8. !define /IfNDef RESTART_NO_HANG 2
  9. !define /IfNDef RESTART_NO_PATCH 4
  10. !define /IfNDef RESTART_NO_REBOOT 8 ; Do not restart the process when the system is rebooted due to patch installations
  11. !define /IfNDef RECOVERY_DEFAULT_PING_INTERVAL 5000
  12. !define /IfNDef /math RECOVERY_MAX_PING_INTERVAL 5000 * 60
  13. /**************************************************
  14. RestartManager.h
  15. **************************************************/
  16. !define RM_SESSION_KEY_LEN 16
  17. !define CCH_RM_SESSION_KEY 32
  18. !define CCH_RM_MAX_APP_NAME 255
  19. !define CCH_RM_MAX_SVC_NAME 63
  20. !define RM_INVALID_TS_SESSION -1
  21. !define RM_INVALID_PROCESS -1
  22. !define RmUnknownApp 0
  23. !define RmMainWindow 1
  24. !define RmOtherWindow 2
  25. !define RmService 3
  26. !define RmExplorer 4
  27. !define RmConsole 5
  28. !define RmCritical 1000 ; Application is critical system process where a reboot is required to restart
  29. !define RmForceShutdown 0x1 ; Force unresponsive applications and services to shut down after the timeout period
  30. !define RmShutdownOnlyRegistered 0x10 ; Only shutdown apps if all apps registered for restart (RegisterApplicationRestart)
  31. !define RmStatusUnknown 0
  32. !define RmStatusRunning 1
  33. !define RmStatusStopped 2 ; Application stopped by Restart Manager
  34. !define RmStatusStoppedOther 4
  35. !define RmStatusRestarted 8
  36. !define RmStatusErrorOnStop 0x10
  37. !define RmStatusErrorOnRestart 0x20
  38. !define RmStatusShutdownMasked 0x40
  39. !define RmStatusRestartMasked 0x80
  40. !define RmRebootReasonNone 0
  41. !define RmRebootReasonPermissionDenied 1
  42. !define RmRebootReasonSessionMismatch 2
  43. !define RmRebootReasonCriticalProcess 4
  44. !define RmRebootReasonCriticalService 8
  45. !define RmRebootReasonDetectedSelf 0x10
  46. !define SYSSIZEOF_RM_UNIQUE_PROCESS 12
  47. !define SYSSTRUCT_RM_UNIQUE_PROCESS (i,l)
  48. !include LogicLib.nsh
  49. !include Util.nsh
  50. !macro RestartManager_StartSession outvarhandle
  51. System::Call 'RSTRTMGR::RmStartSession(*i-1s, i0, w)i.s'
  52. Pop ${outvarhandle}
  53. ${If} ${outvarhandle} <> 0
  54. ${OrIf} ${outvarhandle} == error
  55. Pop ${outvarhandle}
  56. Push ""
  57. ${EndIf}
  58. Pop ${outvarhandle}
  59. !macroend
  60. !macro RestartManager_EndSession handle
  61. System::Call 'RSTRTMGR::RmEndSession(i${handle})'
  62. !macroend
  63. !macro RestartManager_RegisterFile handle path
  64. System::Call 'RSTRTMGR::RmRegisterResources(i${handle},i1,*ws,i0,p0,i0,p0)i.r0' "${path}"
  65. !macroend
  66. !macro RestartManager_Shutdown handle
  67. System::Call 'RSTRTMGR::RmShutdown(i${handle}, i${RmForceShutdown}, p0)'
  68. !macroend
  69. !macro RestartManager_Restart handle
  70. System::Call 'RSTRTMGR::RmRestart(i${handle}, i0, p0)'
  71. !macroend
  72. !macro RestartManager_ShutdownFile fullpath outvar_errcode
  73. Push "${fullpath}"
  74. !insertmacro CallArtificialFunction RestartManager_ShutdownFileImp
  75. Pop ${outvar_errcode}
  76. !macroend
  77. !macro RestartManager_ShutdownFileImp
  78. Exch $1
  79. Push $0
  80. System::Call 'RSTRTMGR::RmStartSession(*i-1s, i0, w)i.r0'
  81. ${If} $0 == error
  82. Pop $0
  83. StrCpy $0 1150
  84. ${Else}
  85. System::Call 'RSTRTMGR::RmRegisterResources(isr1,i1,*wr1,i0,p0,i0,p0)i.r0'
  86. ${If} $0 = 0
  87. System::Call 'RSTRTMGR::RmShutdown(ir1, i${RmForceShutdown}, p0)i.r0'
  88. ${EndIf}
  89. System::Call 'RSTRTMGR::RmEndSession(ir1)'
  90. ${EndIf}
  91. Exch
  92. Pop $1
  93. Exch $0
  94. !macroend
  95. !endif ;~ Include guard