WMI를 사용하여 Configuration Manager 사이트 제어 파일에 읽고 쓰는 방법

Configuration Manager 클래스 메서드를 사용하여 WMI(Windows Management Instrumentation)를 사용하여 SMS_SiteControlFile 사이트 제어 파일에 씁니다.

WMI를 사용하여 사이트 제어 파일에 쓸 때 세션 핸들을 사용하여 애플리케이션을 식별합니다. 파일에 대한 동시 업데이트를 관리하는 데 사용됩니다.

사이트 제어 파일에 대한 쓰기를 마쳤으면 변경 내용을 커밋해야 합니다.

SMS_SiteControlFile 사이트 제어 파일의 변경 내용을 관리하는 다음 방법이 있습니다.

방법 설명
CommitSCF 변경 내용을 Configuration Manager 데이터베이스에 적용합니다.
RefreshSCF Configuration Manager 데이터베이스의 최근 변경 내용으로 사이트 제어 파일의 메모리 내 복사본을 새로 고칩니다.
GetSessionHandle 사이트 제어 파일 및 세션 핸들의 메모리 내 복사본을 가져옵니다. 모든 IWbemServices 메서드에 전달되는 개체에 IWbemContext 세션 핸들을 배치합니다.
ReleaseSessionHandle 사이트 제어 파일의 메모리 내 복사본과 세션 핸들과 연결된 모든 리소스를 해제합니다.

주의

SMS 공급자 클래스를 사용하여 사이트 구성을 수정하기 전에 사이트 구성을 관리하는 경험이 있어야 합니다. 구성 가능한 항목을 변경하여 사이트에 큰 피해를 줄 수 있습니다. 주의를 기울이거나 및 SMS_SCI_SiteDefinition 클래스를 SMS_SCI_FileDefinition 모두 사용하지 않아야 합니다. 이러한 클래스는 사이트 제어 파일 자체를 관리합니다. 주의하지 않으면 사이트를 쓸모 없게 렌더링할 수 있습니다.

사이트 제어 파일에 쓰려면

  1. SMS 공급자에 대한 연결을 설정합니다. 자세한 내용은 SMS 공급자 기본 사항을 참조하세요.

  2. SWbemNameValue 컨텍스트 데이터를 저장할 값 집합을 만듭니다.

  3. 클래스 GetSessionHandle에서 세션 핸들을 SMS_SiteControlFile 가져옵니다.

  4. 컨텍스트 데이터에 세션 핸들을 추가합니다.

  5. 개체 RefreshSCFSMS_SiteControlFile 호출하여 사이트 제어 파일의 최신 복사본을 가져옵니다. 호출에서 컨텍스트 데이터를 사용합니다.

  6. 컨텍스트 데이터를 사용하여 업데이트하려는 사이트 제어 파일 리소스를 쿼리합니다.

  7. 컨텍스트 데이터를 사용하여 리소스를 업데이트합니다.

  8. 개체 메서드를 사용하여 SMS_SiteControlFile 사이트 제어 파일에 변경 내용을 커밋합니다 CommitSCF .

  9. 개체 ReleaseSessionHandle 메서드를 SMS_SiteControlFile 호출하여 세션 핸들을 해제합니다.

예시

다음 VBScript 예제에서는 사이트 제어 파일의 클라이언트 에이전트 구성 요소에 액세스하고 더미 속성, 속성 목록 및 다중 문자열 목록을 만듭니다. 그런 다음, 만들어진 업데이트를 제거합니다. 이 예제에서는 세션 핸들을 설정하고, 사이트 제어 파일을 가져와서 사이트 제어 파일을 쿼리하고, 업데이트하고, 사이트 제어 파일을 변경한 내용을 커밋하는 방법을 보여 줍니다.

예제 LocaleID 에서 속성은 영어(미국)로 하드 코딩됩니다. 미국 이외 지역의 로캘이 필요한 경우 설치를 SMS_Identification 서버 WMI 클래스LocaleID 속성에서 가져올 수 있습니다.

샘플 코드 호출에 대한 자세한 내용은 코드 조각 Configuration Manager 호출을 참조하세요.

Sub ReadWriteScf(connection, siteCode)  

    Dim context  
    Dim query  
    Dim resource  
    Dim resources  
    Dim inParams  

    Set context = CreateObject("WbemScripting.SWbemNamedValueSet")  

    ' Add the standard SMS context qualifiers to the context object.  
    context.Add "LocaleID", "MS\1033"  
    context.Add "MachineName", "MyMachine"  
    context.Add "ApplicationName", "MyApp"  

    ' Add the session handle.  
    context.Add "SessionHandle", _  
         connection.ExecMethod("SMS_SiteControlFile", "GetSessionHandle").SessionHandle  

   ' Load site control file.  
       Set inParams = connection.Get("SMS_SiteControlFile").Methods_("RefreshSCF").InParameters.SpawnInstance_  
InParams.SiteCode = siteCode  
connection.ExecMethod "SMS_SiteControlFile", "RefreshSCF", inParams, , context  

    ' Query for the client agent component.  
    query = "SELECT * FROM SMS_SCI_ClientComp " & _  
            "WHERE ClientComponentName = 'Client Agent' " & _  
           "AND SiteCode = '" & siteCode & "'"  

    Set resources = connection.ExecQuery(query, , , context)             

    For each resource in resources  

    ' Embedded property.  

        WScript.Echo "Embedded property"  
        Wscript.Echo "-----------------"  

        Dim value  
        Dim value1  
        Dim value2  

        Call WriteScfEmbeddedProperty(connection,context,resource,"Test2",20,"Hello","World")  

        If  GetScfEmbeddedProperty(resource,"Test2",value,value1,value2) = True Then  
            Wscript.Echo "Value: " + CStr(value)  
            WScript.Echo "Value1: " + value1  
            WScript.Echo "Value2: " + value2  
        End If  

        WScript.Echo   
        dim n,l  
        dim updatedProps   
        Dim scfProp  

        n = 0  
        ' Remove the property.  
        For l = 0 To UBound (resource.Props)   

            ' Copy each element except the one to delete.  
            If resource.Props(l).PropertyName <> "Test2" Then  
                Dim embeddedProperty  
                Set embeddedProperty = connection.Get("SMS_EmbeddedProperty").Spawninstance_()  
                If l = 0 Then  
                    ' Create an array to copy to.  
                    updatedProps = array(embeddedProperty)  
                    Redim updatedProps(Ubound(resource.Props)-1)  
                End If  
                ' Copy the element.  
                embeddedProperty.PropertyName = resource.Props(l).PropertyName  
                embeddedProperty.Value = resource.Props(l).value  
                embeddedProperty.Value1 = resource.Props(l).value1  
                embeddedProperty.Value2 = resource.Props(l).value2  

                Set updatedProps(n) = embeddedProperty  
                n = n + 1  
          End If    
        Next    

        ' Update  
        resource.Props = updatedProps  
        resource.Put_, context  

        WScript.Echo         

        ' Check that the property has been deleted.   
        If  GetScfEmbeddedProperty(resource,"Test2",value,value1,value2) = True Then  
            WScript.Echo "Property found"  
        Else  
            WScript.Echo "Property not found"  
        End If      

        WScript.Echo   

    ' Embedded property list.  

        WScript.Echo "Embedded property list"  
        WScript.Echo "----------------------"  

        Dim values  
        values = Array("Tiger","Wolf")  

        Call WriteScfEmbeddedPropertyList(connection,context,resource,"Animals",values)  

        Dim retrievedValues   

        If GetScfEmbeddedPropertyList(resource,"Animals",retrievedValues) = True Then  
            Dim i,c  
            Dim updatedValues  

            c = 0   

            ' Display the list and remove the property Tiger.  
            updatedValues = Array(UBound(retrievedValues)-1)  
            For i = 0 To  UBound (retrievedValues)  
                 Wscript.Echo retrievedValues(i)  
                 If retrievedValues(i) <> "Tiger" Then  

                    updatedValues(c) = retrievedValues(i)  
                    c = c + 1  
                 End If     
            Next  

            WScript.Echo  
            ' Update the property list.  
            Call WriteScfEmbeddedPropertyList(connection,context,resource,"Animals",updatedValues)  

            ' Get the property list and display.  
            Call GetScfEmbeddedPropertyList(resource,"Animals",retrievedValues)  

            For i = 0 To  UBound (retrievedValues)  
                 Wscript.Echo retrievedValues(i)  
             Next  
        Else  
            WScript.Echo "Not found"  
        End If   

        WScript.Echo          

    ' RegMultiString list.          

        WScript.Echo "Embedded RegMultiString list"  
        WScript.Echo "----------------------------"  

        Dim valueStrings  
        valueStrings= Array("Lisa","Julie")  

        ' Write the RegMultiString list.  
        Call WriteScfRegMultiStringList(connection,context,resource,"Names2",valueStrings)  

        Dim retrievedValueStrings   

        ' Get the RegMultiString list.            
        If GetScfRegMultiStringList(resource,"Names2",retrievedValueStrings) = True Then  

            Dim updatedValueStrings  

            c = 0   
            updatedValueStrings = Array(Ubound(retrievedValueStrings)-1)  
            For i = 0 To UBound (retrievedValueStrings)  
                 Wscript.Echo retrievedValueStrings(i)  
                 if retrievedValueStrings(i) <> "Lisa" Then  
                    updatedValueStrings(c) = retrievedValueStrings(i)  
                 End If  
            Next   

            Call WriteScfRegMultiStringList(connection,context,resource,"Names",updatedValueStrings)  

            WScript.Echo   

            Call GetScfRegMultiStringList(resource,"Names",retrievedValueStrings)  

            For i = 0 To UBound (retrievedValueStrings)  
                 Wscript.Echo retrievedValueStrings(i)  
             Next   
        Else  
            WScript.Echo "Not found"              
        End If     
    Next  

    ' Commit the changes.  
    Set inParams = connection.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_  
    inParams.SiteCode = siteCode  
    connection.ExecMethod "SMS_SiteControlFile", "CommitSCF", inParams, , context  

    ' Release the session handle.  
    Set inParams = connection.Get("SMS_SiteControlFile").Methods_("ReleaseSessionHandle").InParameters.SpawnInstance_  
    inParams.SessionHandle = context.Item("SessionHandle")  
    connection.ExecMethod "SMS_SiteControlFile", "ReleaseSessionHandle", inParams    
End Sub  

예제 메서드에는 다음 매개 변수가 있습니다.

매개 변수 형식 설명
connection - SWbemServices SMS 공급자에 대한 유효한 연결입니다.
siteCode - String Configuration Manager 사이트의 사이트 코드입니다.

코드 컴파일

이 C# 예제에는 다음이 필요합니다.

네임 스페이스

시스템

System.Collections.Generic

System.Collections

System.Text

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

어셈블리

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

강력한 프로그래밍

오류 처리에 대한 자세한 내용은 Configuration Manager 오류 정보를 참조하세요.

.NET Framework 보안

Configuration Manager 애플리케이션 보안에 대한 자세한 내용은 역할 기반 관리 Configuration Manager 참조하세요.

참고 항목

Windows 관리 계측
Configuration Manager 사이트 제어 파일 정보
Configuration Manager 사이트 제어 파일 포함된 속성 목록을 읽는 방법