다음을 통해 공유


WMI 컬렉션에서 단일 항목 제거

컬렉션에 액세스하는 주요 목적 중 하나는 컬렉션에서 항목을 제거하는 것입니다. SWbemPropertySet.Remove 메서드를 호출하여 컬렉션에서 항목을 제거할 수 있습니다. 이 메서드는 SWbemObjectSet 또는 SWbemMethodSet에 사용할 수 없습니다.

항목은 SWbemPropertySet, SWbemQualifierSetSWbemNamedValueSet에서 이름별로 제거됩니다. 그러나 SWbemRefresher의 항목은 권한 이름을 나타내는 상수에 의해 SWbemPrivilegeSet에서 인덱스별로 제거됩니다.

컬렉션에서 항목을 제거하려면

  • 다음 코드 예제는 SWbemPropertySet.Remove 메서드를 호출하여 항목을 제거하는 방법을 보여줍니다.

    oclass.Properties_.Remove "Prop2"
    

    다음 예제에서는 root\default 네임스페이스에 ‘NewClass’라는 새 클래스를 만들고 이 클래스에 세 개의 속성을 추가합니다. 그런 다음, 스크립트는 이전 예제의 코드를 사용하여 두 번째 속성을 삭제합니다.

    ' Obtain an empty class and name it
    Const WBEM_CIMTYPE_STRING = 8
    Set objSWbemService = GetObject("winmgmts:root\default")
    Set objClass = objSWbemService.get()
    Wscript.Echo "Creating class NewClass"
    objClass.Path_.Class = "NewClass"
    
    ' Add three properties 
    For i = 1 to 3
        objClass.Properties_.Add "Prop" & i, WBEM_CIMTYPE_STRING
    Next
    Getprops()
    
    ' Remove the Prop2 property
    objClass.Properties_.Remove "Prop2"
    Wscript.Echo "Second property removed "
    Getprops()
    
    ' Write the changes to the class back
    objClass.Put_
    
    Sub Getprops()
        Wscript.Echo "Number of Properties = " _
            & objClass.Properties_.Count
        For Each prop in objClass.Properties_
            Wscript.Echo prop.name
        Next
    End Sub
    

자세한 내용은 클래스 및 인스턴스 정보 조작, 컬렉션 액세스컬렉션에서 여러 항목 제거를 참조하세요.