Aracılığıyla paylaş


Configuration Manager'da Bilgisayar Değişkeni Oluşturma

SMS_MachineSettings sınıf MachineVariables dizisi özelliğine SMS_MachineVariable örnekleri ekleyerek Configuration Manager çalıştıran bir bilgisayar için bir bilgisayar değişkeni oluşturursunuz.

Bilgisayar değişkeni oluşturmak için

  1. SMS Sağlayıcısı ile bağlantı kurun. Daha fazla bilgi için bkz. SMS Sağlayıcısı ile ilgili temel bilgiler.

  2. örneğini SMS_MachineSettingsalın.

  3. Eklenecek her değişken için, ekli nesnenin örneklerini a SMS_MachineVariable dizi özelliğine MachineVariables ekleyin.

  4. Değişiklikleri sınıf örneğine SMS_MachineSettings işleyin.

Örnek

Aşağıdaki örnek yöntem bir koleksiyon değişkeni oluşturur ve bunu sağlanan tanımlayıcı tarafından tanımlanan koleksiyona ekler.

Örnekte LocaleID özelliği İngilizce (ABD) olarak sabit kodlanmıştır. ABD dışındakiler için yerel ayara ihtiyacınız varsa yüklemelerini SMS_Identification Sunucusu WMI SınıfıLocaleID özelliğinden alabilirsiniz.

Örnek kodu çağırma hakkında bilgi için bkz. Configuration Manager Kod Parçacıklarını Çağırma.

Sub CreateComputerVariable(connection, siteCode, name, value, mask, computerId)

    Dim computerSettings
    Dim computerVariables
    Dim computerVariable
    Dim Settings

    ' See if the computer settings object already exists. if it does not, create it.
    Set settings = connection.ExecQuery _
      ("Select * From SMS_MachineSettings Where ResourceID = '" & computerID & "'")

    If settings.Count = 0 Then
        Wscript.Echo "Creating computer settings object"
        Set computerSettings = connection.Get("SMS_MachineSettings").SpawnInstance_
        computerSettings.ResourceID = computerId
        computerSettings.SourceSite = siteCode
        computerSettings.LocaleID = 1033
        computerSettings.Put_
    End If

    ' Get the computer settings object.
    Set computerSettings = connection.Get("SMS_MachineSettings.ResourceID='" & computerId &"'" )

    ' Get the computer variables.
    computerVariables=computerSettings.MachineVariables

    ' Create and populate a new computer variable.
    Set computerVariable = connection.Get("SMS_MachineVariable").SpawnInstance_
    computerVariable.Name = name
    computerVariable.Value = value
    computerVariable.IsMasked = mask

    ' Add the new computer variable.
    ReDim Preserve computerVariables (UBound (computerVariables)+1)
    Set computerVariables(UBound(computerVariables)) = computerVariable

    computerSettings.MachineVariables=computerVariables

    computerSettings.Put_

 End Sub
public void CreateComputerVariable(
    WqlConnectionManager connection,
    string siteCode,
    string name,
    string value,
    bool mask,
    int computerId)
{
    try
    {
        // Get the computer settings.
        IResultObject computerSettings=null;

        IResultObject computerSettingsQuery = connection.QueryProcessor.ExecuteQuery(
            "Select * from SMS_MachineSettings where ResourceId = '" + computerId + "'");

        foreach (IResultObject settings in computerSettingsQuery)
        {
            computerSettings = settings;
        }

        if (computerSettings == null) // It does not exist, so create it.
        {
            computerSettings = connection.CreateInstance(@"SMS_MachineSettings");
            computerSettings["ResourceID"].IntegerValue = computerId;
            computerSettings["SourceSite"].StringValue = siteCode;
            computerSettings["LocaleID"].IntegerValue = 1033;
            computerSettings.Put();
            computerSettings.Get();
        }

        // Create the computer variable.
        List<IResultObject> computerVariables = computerSettings.GetArrayItems("MachineVariables");
        IResultObject computerVariable = connection.CreateEmbeddedObjectInstance("SMS_MachineVariable");
        computerVariable["Name"].StringValue = name;
        computerVariable["Value"].StringValue = value;
        computerVariable["IsMasked"].BooleanValue = mask;

        // Add the computer variable to the computer settings.
        computerVariables.Add(computerVariable);
        computerSettings.SetArrayItems("MachineVariables", computerVariables);

        computerSettings.Put();
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to create computer variable: " + e.Message);
        throw;
    }
}

Örnek yöntem aşağıdaki parametrelere sahiptir:

Parametre Tür Açıklama
connection -Yönetilen: WqlConnectionManager
- VBScript: SWbemServices
SMS Sağlayıcısına geçerli bir bağlantı.
siteCode -Yönetilen: String
- VBScript: String
Kaynak sitenin site kodu.
name -Yönetilen: String
- VBScript: String
Oluşturulacak değişkenin adı.
value -Yönetilen: String
- VBScript: String
Değişkenin değeri.
mask -Yönetilen: Boolean
- VBScript: Boolean
Değerin Configuration Manager konsolunda görüntülenip görüntülenmeyeceğini belirtir.

true - değişken değeri görüntülenmez.

false - değişken değeri görüntülenir.
computerID -Yönetilen: Integer
- VBScript: Integer
Bilgisayar tanımlayıcısı. Bu genellikle SMS_R_System sınıfı ResourceID özelliğidir.

Kodu Derleme

C# örneğinde aşağıdaki derleme gereksinimleri vardır:

Ad Alanları

Sistem

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Meclis

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Sağlam Programlama

Hata işleme hakkında daha fazla bilgi için bkz . Configuration Manager Hataları Hakkında.

.NET Framework Güvenliği

Configuration Manager uygulamalarının güvenliğini sağlama hakkında daha fazla bilgi için bkz. Configuration Manager rol tabanlı yönetim.

Ayrıca bkz.

İşletim sistemi dağıtımı bilgisayar yönetimi hakkında