다음을 통해 공유


프로그램에 대해 지원되는 플랫폼을 수정하는 방법

애플리케이션은 및 SMS_Program 클래스의 특정 인스턴스를 가져온 다음 클래스의 SMS_Package 인스턴스를 속성에 추가하여 Configuration Manager 패키지에 SMS_OS_DetailsSupportedOperatingSystems 지원되는 플랫폼을 추가할 수 있습니다.

프로그램에 대해 지원되는 플랫폼을 수정하려면

  1. SMS 공급자에 대한 연결을 설정합니다.

  2. 클래스를 사용하여 기존 패키지 개체를 SMS_Package 가져옵니다.

  3. 클래스를 사용하여 기존 프로그램 개체를 SMS_Program 가져옵니다.

  4. 클래스의 SMS_OS_Details 인스턴스를 만들고 채웁니다.

  5. 프로그램 개체의 속성에 SupportedOperatingSystemsSMS_OS_Details 인스턴스를 추가합니다(3단계부터).

예시

다음 예제 메서드는 프로그램에 지원되는 플랫폼을 추가하는 방법을 보여 줍니다.

참고

이 예제의 약간의 변형은 특정 패키지와 연결된 모든 프로그램의 속성 값을 변경할 수 있습니다. 예제는 모든 프로그램을 나열하는 방법 및 최대 런타임 값 코드 예제를 참조하세요. 그러나 및 ProgramName를 사용하여 PackageID 특정 프로그램에 액세스하는 보다 효율적인 방법은 프로그램 속성 코드 예제를 참조하세요.

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

Sub ModifySupportedPlatformsForProgram(connection,          _
                                       existingPackageID,   _
                                       existingProgramName, _
                                       newMaxVersion,       _
                                       newMinVersion,       _
                                       newName,             _
                                       newPlatform)

' Define a constant with the hexadecimal value for RUN_ON_ANY_PLATFORM.
    Const wbemFlagReturnImmediately = 16
    Const wbemFlagForwardOnly = 32
    Const RUN_ON_ANY_PLATFORM = &H08000000
    Dim packageQuery
    Dim package
    Dim allProgramsForPackage
    Dim programQuery
    Dim program
    Dim programPath
    Dim checkPlatformValue
    Dim tempSupportedPlatform
    Dim tempSupportedPlatformsArray
    ' Build a query to get the specified package.
     packageQuery = "SMS_Package.PackageID='" & existingPackageID & "'"
    ' Run the query to get the package.
    Set package = connection.Get(packageQuery)
    ' Output package name and ID.
    WScript.Echo "Package ID:     "  & package.PackageID
    WScript.Echo "Package Name:   "  & package.Name
    ' Build a query to get the programs for the package.
    programQuery = "SELECT * FROM SMS_Program WHERE PackageID='" & existingPackageID & "'"
    ' Run the query to get the programs.
    Set allProgramsForPackage = connection.ExecQuery(programQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)
    'The query returns a collection of program objects that needs to be enumerated.
    For Each program In allProgramsForPackage
        If program.ProgramName = existingProgramName Then
            ' Get all program object properties (in this case we specifically need some lazy properties).
            programPath = program.Put_
            programPath = Mid(programPath, InStr(1, programPath, ":") + 1)
            Set program = connection.Get(programPath)
            ' Check whether RUN_ON_ANY_PLATFORM is set.
            checkPlatformValue = (program.ProgramFlags AND RUN_ON_ANY_PLATFORM)
            If checkPlatformValue <> 0 Then
               ' RUN_ON_ANY_PLATFORM is set. Removing RUN_ON_ANY_PLATFORM value.
                program.ProgramFlags = (program.ProgramFlags XOR RUN_ON_ANY_PLATFORM)
            End If
            ' Output the program name that is being checked for supported platforms.
            WScript.Echo "Program Name: "  & program.ProgramName
            ' Create
            Set tempSupportedPlatform = connection.Get("SMS_OS_Details").SpawnInstance_
            ' Populate tempSupportedPlatform values.
            tempSupportedPlatform.MaxVersion = newMaxVersion
            tempSupportedPlatform.MinVersion = newMinVersion
            tempSupportedPlatform.Name       = newName
            tempSupportedPlatform.Platform   = newPlatform
            ' Get the array of supported operating systems.
            tempSupportedPlatformsArray = program.SupportedOperatingSystems
            ' Add the new supported platform values (object) to the temporary array.
            ReDim Preserve tempSupportedPlatformsArray (Ubound(tempSupportedPlatformsArray) + 1)
            Set tempSupportedPlatformsArray(Ubound(tempSupportedPlatformsArray)) = tempSupportedPlatform
            ' Replace the SupportedOperatingSystems object array with the new updated array.
            program.SupportedOperatingSystems = tempSupportedPlatformsArray
            ' Save the program.
            program.Put_
            ' Output success message.
            WScript.Echo "Supported Platforms Updated "
        End If
    Next
End Sub

public void ModifyProgramSupportedPlatforms(WqlConnectionManager connection,
                                    string existingPackageID,
                                    string existingProgramNameToModify,
                                    string newMaxVersion,
                                    string newMinVersion,
                                    string newName,
                                    string newPlatform)
{
    try
    {
        // Define a constant with the hexadecimal value for RUN_ON_ANY_PLATFORM.
        const Int32 RUN_ON_ANY_PLATFORM = 0x08000000;

        // Build query to get the programs for the package.
        string query = "SELECT * FROM SMS_Program WHERE PackageID='" + existingPackageID + "'";

        // Load the specific program to change (programname is a key value and must be unique).
        IResultObject programsForPackage = connection.QueryProcessor.ExecuteQuery(query);

        // The query returns a collection that needs to be enumerated.
        foreach (IResultObject program in programsForPackage)
        {
            // If a match for the program name is found, make the change(s).
            if (program["ProgramName"].StringValue == existingProgramNameToModify)
            {
                // Get all properties, specifically the lazy properties, for the program object.
                program.Get();

                // Check whether RUN_ON_ANY_PLATFORM is already set.
                Int32 checkPlatformValue = (program["ProgramFlags"].IntegerValue & RUN_ON_ANY_PLATFORM);

                if (checkPlatformValue != 0)
                {
                    // RUN_ON_ANY_PLATFORM is set. Removing RUN_ON_ANY_PLATFORM value.
                    program["ProgramFlags"].IntegerValue = program["ProgramFlags"].IntegerValue ^ RUN_ON_ANY_PLATFORM;
                }

                // Create a new array list to hold the supported platform window objects.
                List<IResultObject> tempSupportedPlatformsArray = new List<IResultObject>();

                // Create and populate a temporary SMS_OS_Details object with the new operating system values.
                IResultObject tempSupportedPlatformsObject = connection.CreateEmbeddedObjectInstance("SMS_OS_Details");

                // Populate temporary SMS_OS_Details object with the new supported platforms values.
                tempSupportedPlatformsObject["MaxVersion"].StringValue = newMaxVersion;
                tempSupportedPlatformsObject["MinVersion"].StringValue = newMinVersion;
                tempSupportedPlatformsObject["Name"].StringValue = newName;
                tempSupportedPlatformsObject["Platform"].StringValue = newPlatform;

                // Populate the local array list with the existing supported platform objects (type SMS_OS_Details).
                tempSupportedPlatformsArray = program.GetArrayItems("SupportedOperatingSystems");

                // Add the newly created service window object to the local array list.
                tempSupportedPlatformsArray.Add(tempSupportedPlatformsObject);

                // Replace the existing service window objects from the target collection with the temporary array that includes the new service window.
                program.SetArrayItems("SupportedOperatingSystems", tempSupportedPlatformsArray);

                // Save the new values in the collection settings instance associated with the Collection ID.
                program.Put();

                // Output program name.
                Console.WriteLine("Modified program: " + program["ProgramName"].StringValue);
            }
        }
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to modify the program. Error: " + ex.Message);
        throw;
    }
}

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

매개 변수 형식 설명
connection -관리: WqlConnectionManager
- VBScript: SWbemServices
SMS 공급자에 대한 유효한 연결입니다.
existingPackageID -관리: String
-Vbscript: String
기존 패키지의 패키지 ID입니다.
existingProgramName -관리: String
-Vbscript: String
기존 프로그램의 프로그램 이름입니다.
newMaxVersion -관리: String
-Vbscript: String
지원되는 최대 버전입니다.
newMinVersionsion -관리: String
-Vbscript: String
지원되는 최소 버전입니다.
newName -관리: String
-Vbscript: String
수정된 프로그램 이름입니다.
newPlatform -관리: String
-Vbscript: String
새 플랫폼입니다.

코드 컴파일

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

네임 스페이스

시스템

System.Collections.Generic

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

어셈블리

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Mscorlib

강력한 프로그래밍

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

참고 항목

소프트웨어 배포 개요