ServiceCreate

##=
# The variable $Bit will hold either 64 or 32 depending on system architecture 
# This is used with all the ${Service::} macros
# Use this in the beginning of your code.
# This snippet should only be used once.
#
Var Bit
System::Call "kernel32::GetCurrentProcess()i.s"
System::Call "kernel32::IsWow64Process(is,*i.r0)"
StrCmpS $0 0 +3
StrCpy $Bit 64
Goto +2
StrCpy $Bit 32

##= 
#= Service::Create
#
# USAGE:
# ${Service::Create} "NAME" "PATH" "TYPE" "START" "DEPEND" /DISABLEFSR $0 $1
#
#    ::Create    = Creates a service entry in the registry and Service Database
#    NAME        = The Service name
#    PATH        = BinaryPathName to the .exe file
#    TYPE        = own|share|interact|kernel|filesys|rec
#    START       = boot|system|auto|demand|disabled|delayed-auto
#    DEPEND      = Dependencies(separated by / (forward slash))
#    /DISABLEFSR = Disables redirection if x64. Use "" to skip.
#    $0          = Return after call
#    $1          =   ''    ''    ''
#
!define Service::Create `!insertmacro _Service::Create`
!macro _Service::Create _SVC _PATH _TYPE _START _DEPEND _FSR _ERR1 _ERR2
    StrCmpS $Bit 64 0 +7
    StrCmp "${_FSR}" /DISABLEFSR 0 +6
        StrCmp "${_DEPEND}" "" 0 +3
        ExecDos::Exec /TOSTACK /DISABLEFSR `"${SC}" create "${_SVC}" DisplayName= "${FULLNAME}" binpath= "${_PATH}" type= "${_TYPE}" start= "${_START}"`
        Goto +7
        ExecDos::Exec /TOSTACK /DISABLEFSR `"${SC}" create "${_SVC}" DisplayName= "${FULLNAME}" binpath= "${_PATH}" type= "${_TYPE}" start= "${_START}" depend= ""${_DEPEND}""`
        Goto +5
    StrCmp "${_DEPEND}" "" 0 +3
    ExecDos::Exec /TOSTACK `"${SC}" create "${_SVC}" DisplayName= "${FULLNAME}" binpath= "${_PATH}" type= "${_TYPE}" start= "${_START}"`
    Goto +2
    ExecDos::Exec /TOSTACK `"${SC}" create "${_SVC}" DisplayName= "${FULLNAME}" binpath= "${_PATH}" type= "${_TYPE}" start= "${_START}" depend= ""${_DEPEND}""`
    Pop ${_ERR1}
    Pop ${_ERR2}
!macroend

/ DISABLEFSR 引數只應在 x64 計算機上使用。但是,如果你陷入困境,那麼巨集中的故障保護會為你躲避這個子彈。這適用於此處列出的服務巨集。