// control.inc = SYSTEM\CurrentControlSet\Control routines

//
//	Add a Group to the GroupServiceOrder
//
//		$0 = Group
//		$1 = BeforeGroup - If Empty add it to the end
//
//
[AddGroupToServiceGroupOrder]

	read-syms GlobalRegistryConstants

	set GroupToAdd = $($0)
	set BeforeGroup = $($1)

	set Added = FALSE

	_Enter("AddGroupToServiceGroupOrder", _Show(GroupToAdd)_Show(BeforeGroup))

	_OpenRegKey_HKLM($(KEY_SERVICEGROUPORDER), KeyServiceGroupOrder)
	_IfValidKey($(KeyServiceGroupOrder))


		_GetRegMultiSzByKey $(KeyServiceGroupOrder) "List"
		_Assert($($R0))
	    set TmpList = $($R1)

		set OldList = {}
		ForListDo $(TmpList)
			set OldList = >($(OldList), $($))
		EndForListDo

	    _Trace("AddGroupToServiceGroupOrder", _Show(OldList))
		
		Ifcontains(i) $(GroupToAdd) not-in $(OldList)

			ifstr $(BeforeGroup) == EMPTY_LIST

				set NewGroupList = >($(OldList), $(GroupToAdd) )
				set Added = TRUE

			else

				set NewGroupList = {}
				ForListDo $(OldList)
					ifstr(i) $($) == $(BeforeGroup)
						set NewGroupList = >($(NewGroupList), $(GroupToAdd) )
						set Added = TRUE
					endif
					set NewGroupList = >($(NewGroupList), $($))
				EndForListDo

			endif

			_Trace("AddGroupToServiceGroupOrder", _Show(NewGroupList))
	        _SetRegMultiSzByKey $(KeyServiceGroupOrder) "List" $(NewGroupList)
           _Assert($($R0))

		else

			set Added = TRUE

		endif

		CloseRegKey $(KeyServiceGroupOrder)
	
	endif

	_Exit("AddGroupToServiceGroupOrder", _Show(Added))
	Return $(Added) 

//
//	Remove a Group from the GroupServiceOrder
//
//		$0 = Group
//
//
[RemoveGroupFromServiceGroupOrder]

	read-syms GlobalRegistryConstants

	set GroupToRemove = $($0)
	set NewGroupList = {}

	_Enter("RemoveGroupFromServiceGroupOrder", _Show(GroupToRemove))

	_OpenRegKey_HKLM($(KEY_SERVICEGROUPORDER), KeyServiceGroupOrder)
	_IfValidKey($(KeyServiceGroupOrder))

		_GetRegMultiSzByKey $(KeyServiceGroupOrder) "List"
		_Assert($($R0))
	    set TmpList = $($R1)

		ForListDo $(TmpList)
			ifstr(i) $(GroupToRemove) != $($)
				set NewGroupList = >($(NewGroupList), $($))
			Endif
		EndForListDo

	    _SetRegMultiSzByKey $(KeyServiceGroupOrder) "List" $(NewGroupList)
       _Assert($($R0))

		CloseRegKey $(KeyServiceGroupOrder)
	
	endif

	_Exit("RemoveGroupFromServiceGroupOrder", _Show(NewGroupList))
	Return 
