[RegistryConstants]
    MaskAllAccess          = 33554432
    NoTitle                = 0
    RegLastError           = $(!REG_ERROR_SUCCESS)
[GetNTSource]
    set Status = STATUS_SUCCESSFUL
    read-syms RegistryConstants
    set NTSource = A:\
    set KeyName = "Software\Microsoft\Windows NT\CurrentVersion"
    OpenRegKey $(!REG_H_LOCAL) "" $(KeyName) $(!REG_KEY_READ) KeyHandle
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        Debug-Output "REGISTRY.INF: Couldn't open windows nt software key for read access"
        goto end_getntsource
    endif
    GetRegValue $(KeyHandle) "SourcePath" SourcePathValue
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        CloseRegKey $(KeyHandle)
        goto end_getntsource
    endif
    set NTSource =  *($(SourcePathValue), 4)
    CloseRegKey $(KeyHandle)
end_getntsource = +
    Return $(Status) $(NTSource)
[MakeServicesEntry]
    set Status = STATUS_FAILED
    read-syms RegistryConstants
    Debug-Output "REGISTRY.INF: Creating Services node: "$($0)
    OpenRegKey $(!REG_H_LOCAL) "" "system\"$(!STF_CONTROLSET)"\services" $(MaskAllAccess) ServicesKey
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        Debug-Output "REGISTRY.INF: Failed to open services key"
        goto finish_MakeServicesEntry
    endif
    set StandardSet = { Type,           +
                        Start,          +
                        ErrorControl,   +
                        Group,          +
                        Dependencies,   +
                        StartName,      +
                        Password,       +
                        BinaryPathName, +
                        DisplayName     +
                      }
    ForListDo $(StandardSet)
        set $($) = ""
    EndForListDo
    set KeyValues = {}
    ForListDo $($1)
       set Var   = *($($), 1)
       set Value = *($($), 4)
       ifcontains(i) $(Var) in $(StandardSet)
           set $(Var) = $(Value)
       else
           set KeyValues = >($(KeyValues), $($))
       endif
    EndForListDo
    set Error = NO
    ForListDo { Type, Start, ErrorControl, BinaryPathName }
        ifstr(i) $($($)) == ""
            set Error = YES
        endif
    EndForListDo
    ifstr(i) $(Error) == YES
        Debug-Output "REGISTRY.INF: MakeServicesEntry was not passed in one of the three values: Type, Start, ErrorControl"
        CloseRegKey $(ServicesKey)
        goto finish_MakeServicesEntry
    endif
    set ServiceName = $($0)
    LibraryProcedure STATUS, $(!LIBHANDLE), SetupCreateService $(ServiceName)      +
                                                               $(DisplayName)      +
                                                               $(Type)             +
                                                               $(Start)            +
                                                               $(ErrorControl)     +
                                                               $(BinaryPathName)   +
                                                               $(Group)            +
                                                               $(Dependencies)     +
                                                               $(StartName)        +
                                                               $(Password)
    ifstr(i) $(STATUS) != "SUCCESS"
        Debug-Output "REGISTRY.INF: MakeServicesEntry: SetupCreateService function failed"
        CloseRegKey $(ServicesKey)
        goto finish_MakeServicesEntry
    endif
    set KeyPath   = {{$($0), $(NoTitle), $(MaskAllAccess)}}
    shell "" CreateKey $(ServicesKey) $(KeyPath) $(KeyValues)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "REGISTRY.INF: Failed to shell CreateKey."
        CloseRegKey $(ServicesKey)
        goto error_MakeServicesEntry
    endif
    ifstr(i) $($R0) != STATUS_SUCCESSFUL
        Debug-Output "REGISTRY.INF: Failed to create services node."
        CloseRegKey $(ServicesKey)
        goto error_MakeServicesEntry
    endif
    set MiniportKey = $($R1)
    ifstr(i) $($2) != ""
        set KeyPath   = {{$($5), $(NoTitle), $(MaskAllAccess)}}
        set KeyValues = $($2)
        shell "" CreateKey $(MiniportKey) $(KeyPath) $(KeyValues)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            CloseRegKey $(ServicesKey)
            CloseRegKey $(MiniportKey)
            goto error_MakeServicesEntry
        endif
        ifstr(i) $($R0) != STATUS_SUCCESSFUL
            CloseRegKey $(ServicesKey)
            CloseRegKey $(MiniportKey)
            goto error_MakeServicesEntry
        endif
        set ParametersKey = $($R1)
        ForListDo $($3)
            set-sub DeviceNum = $(#) 1
            set EntryName = "Device"$(DeviceNum)
            set KeyPath   = {{$(EntryName), $(NoTitle), $(MaskAllAccess)}}
            set KeyValues = $($3)
            shell "" CreateKey $(ParametersKey) $(KeyPath) $(KeyValues)
            ifint $($ShellCode) != $(!SHELL_CODE_OK)
                CloseRegKey $(ServicesKey)
                CloseRegKey $(MiniportKey)
                CloseRegKey $(ParametersKey)
                goto error_MakeServicesEntry
            endif
            ifstr(i) $($R0) != STATUS_SUCCESSFUL
                CloseRegKey $(ServicesKey)
                CloseRegKey $(MiniportKey)
                CloseRegKey $(ParametersKey)
                goto error_MakeServicesEntry
            endif
            CloseRegKey $($R1)
        EndForListDo
        CloseRegKey $(ParametersKey)
    endif
    CloseRegKey $(MiniportKey)
    ifstr(i) $($4) != {}
        OpenRegKey $(ServicesKey) "" "eventlog\system" $(MaskAllAccess) EventLogKey
        ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
            Debug-Output "REGISTRY.INF: Failed to open eventlog key"
            CloseRegKey $(ServicesKey)
            goto error_MakeServicesEntry
        endif
        set KeyPath   = {{$($0), $(NoTitle), $(MaskAllAccess)}}
        set KeyValues = $($4)
        shell "" CreateKey $(EventLogKey) $(KeyPath) $(KeyValues)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            CloseRegKey $(ServicesKey)
            CloseRegKey $(EventLogKey)
            goto error_MakeServicesEntry
        endif
        ifstr(i) $($R0) != STATUS_SUCCESSFUL
            CloseRegKey $(ServicesKey)
            CloseRegKey $(EventLogKey)
            goto error_MakeServicesEntry
        endif
        CloseRegKey $($R1)
        CloseRegKey $(EventLogKey)
    endif
    CloseRegKey $(ServicesKey)
    set Status = STATUS_SUCCESSFUL
    goto finish_MakeServicesEntry
error_MakeServicesEntry = +
    shell "" ModifyServicesEntry $($0) $(!SERVICE_DISABLED)
finish_MakeServicesEntry = +
    Return $(Status)
[GetServicesEntryStart]
    set Status     = STATUS_FAILED
    set StartValue = ""
    read-syms RegistryConstants
    Debug-Output "REGISTRY.INF: Get Services node Start value: "$($0)
    set KeyName = "system\"$(!STF_CONTROLSET)"\services\"$($0)
    OpenRegKey $(!REG_H_LOCAL) "" $(KeyName) $(!REG_KEY_READ) KeyHandle
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        Debug-Output "REGISTRY.INF: Couldn't open services node for read access"
        goto finish_GetServicesEntryStart
    endif
    GetRegValue $(KeyHandle) "Start" StartValueList
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        Debug-Output "REGISTRY.INF: Couldn't read Start value"
        CloseRegKey $(KeyHandle)
        goto finish_GetServicesEntryStart
    endif
    CloseRegKey $(KeyHandle)
    set StartValue = *($(StartValueList), 4)
    set Status = STATUS_SUCCESSFUL
finish_GetServicesEntryStart = +
    Return $(Status) $(StartValue)
[RemoveServicesEntry]
    set Status = STATUS_FAILED
    read-syms RegistryConstants
    Debug-Output "REGISTRY.INF: Removing Services node: "$($0)
    shell "" ModifyServicesEntry $($0) $(!SERVICE_DISABLED)
    Return $($R0)
[MakeSetupKey]
    set Status = STATUS_FAILED
    read-syms  RegistryConstants
    OpenRegKey $(!REG_H_LOCAL) "" "system\"$(!STF_CONTROLSET)"\control" $(MaskAllAccess) ControlKey
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        Debug-Output "REGISTRY.INF: Failed to open services key"
        goto finish_MakeSetupKey
    endif
    set KeyPath   = { +
                     {"Setup", $(NoTitle), $(MaskAllAccess)} +
                    }
    set KeyValues = {}
    shell "" CreateKey $(ControlKey) $(KeyPath) $(KeyValues)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        CloseRegKey $(ControlKey)
        goto finish_MakeSetupKey
    endif
    ifstr(i) $($R0) != STATUS_SUCCESSFUL
        CloseRegKey $(ControlKey)
        goto finish_MakeSetupKey
    endif
    CloseRegKey $($R1)
    CloseRegKey $(ControlKey)
    set Status = STATUS_SUCCESSFUL
finish_MakeSetupKey = +
    Return $(Status)
[CheckSetupModify]
    set Status = STATUS_FAILED
    read-syms  RegistryConstants
    LibraryProcedure STATUS, $(!LIBHANDLE), TestAdmin
    ifstr(i) $(STATUS) == "YES"
        set Status = STATUS_SUCCESSFUL
    endif
    Return $(Status)
[MakeSetupOptionEntry]
    set Status = STATUS_FAILED
    read-syms  RegistryConstants
    OpenRegKey $(!REG_H_LOCAL) "" "system\"$(!STF_CONTROLSET)"\control" $(MaskAllAccess) ControlKey
    ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
        Debug-Output "REGISTRY.INF: Failed to open services key"
        goto finish_MakeSetupOptionEntry
    endif
    set KeyPath   = { +
                     {"Setup", $(NoTitle), $(MaskAllAccess)} +
                    }
    set KeyValues = { +
                      {$($0), $(NoTitle), $(!REG_VT_SZ), $($1)} +
                    }
    shell "" CreateKey $(ControlKey) $(KeyPath) $(KeyValues)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        CloseRegKey $(ControlKey)
        goto finish_MakeSetupOptionEntry
    endif
    ifstr(i) $($R0) != STATUS_SUCCESSFUL
        CloseRegKey $(ControlKey)
        goto finish_MakeSetupOptionEntry
    endif
    CloseRegKey $($R1)
    CloseRegKey $(ControlKey)
    set Status = STATUS_SUCCESSFUL
finish_MakeSetupOptionEntry = +
    Return $(Status)
[ModifyServicesEntry]
    read-syms RegistryConstants
    set Status = STATUS_FAILED
    set StartValue = $($1)
    LibraryProcedure STATUS, $(!LIBHANDLE), SetupChangeServiceStart $($0) $(StartValue)
    ifstr(i) $(STATUS) != "SUCCESS"
        Debug-Output "REGISTRY.INF: ModifyServicesEntry: SetupChangeServiceStart function failed"
        goto finish_ModifyServicesEntry
    endif
    set Status = STATUS_SUCCESSFUL
finish_ModifyServicesEntry = +
    Return $(Status)
[CreateKey]
    set Status = STATUS_FAILED
    read-syms RegistryConstants
    set BaseHandle = $($0)
    set KeyHandle  = $(BaseHandle)
    ForListDo $($1)
        set KeyInfo = $($)
        set KeyName = *($(KeyInfo), 1)
        OpenRegKey $(BaseHandle) "" $(KeyName) $(MaskAllAccess) KeyHandle
        ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
            Debug-Output "REGISTRY.INF: Key"$(KeyName)"doesn't exist.  Will create key"
            set RegLastError = 0
            CreateRegKey $(BaseHandle) $(KeyInfo) "" $(MaskAllAccess) "" KeyHandle
            ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
                set Status = STATUS_ERROR_CREATEKEY
                Debug-Output "REGISTRY.INF: Error in creating key"
                goto endcreate
            endif
        endif
        ifstr(i) $(BaseHandle) != $($0)
            CloseRegKey $(BaseHandle)
            ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
                set Status = STATUS_ERROR_CREATEKEY
                Debug-Output "REGISTRY.INF: Error in closing base handle"
                goto endcreate
            endif
        endif
        set BaseHandle = $(KeyHandle)
    EndForListDo
    ifstr(i) $($2) != {}
        shell "" AddValueList $(KeyHandle) $($2)
        ifstr(i) $($R0) != STATUS_SUCCESSFUL
            set Status = STATUS_ERROR_CREATEVALUE
            goto endcreate
        endif
    endif
    set Status = STATUS_SUCCESSFUL
endcreate = +
    ifstr(i) $(Status) != STATUS_SUCCESSFUL
        Debug-Output "REGISTRY.INF: CreateKey Error:"$(Status)
    endif
    Return $(Status) $(KeyHandle)
[AddValueList]
   set Status = STATUS_FAILED
   read-syms RegistryConstants
   ForListDo $($1)
       SetRegValue $($0) $($)
       ifint $(RegLastError) != $(!REG_ERROR_SUCCESS)
           Debug-Output "REGISTRY.INF: CreateValue failed:"$($)
           goto end_addvaluelist
       endif
   EndForListDo
   set Status = STATUS_SUCCESSFUL
end_addvaluelist = +
   return $(Status)
[EnableCrashDump]
    OpenRegKey $(!REG_H_LOCAL) "" system\currentcontrolset\control\CrashControl $(!REG_KEY_SET_VALUE) CrashControlKey
    ifstr $(CrashControlKey) != ""
        shell "" AddValueList $(CrashControlKey) {{LogEvent        ,0,$(!REG_VT_DWORD),1},+
                                                  {SendAlert       ,0,$(!REG_VT_DWORD),1},+
                                                  {CrashDumpEnabled,0,$(!REG_VT_DWORD),1},+
                                                  {AutoReboot      ,0,$(!REG_VT_DWORD),1}}
        CloseRegKey $(CrashControlKey)
    endif
    return
