Creación de una implementación

En los ejemplos siguientes se muestra cómo crear una implementación de Configuration Manager con la clase SMS_Advertisement y sus propiedades.

Importante

La cuenta que crea la implementación necesita el permiso Implementar paquetes para la colección y el permiso De lectura para el paquete.

Información general

  1. Configure una conexión con el proveedor de SMS.

  2. Cree un nuevo objeto de la SMS_Advertisement clase .

  3. Rellene las nuevas propiedades del anuncio.

  4. Guarde el nuevo anuncio y las propiedades.

Ejemplos

En los ejemplos siguientes se crea un anuncio para la distribución de software.

Para obtener más información sobre cómo llamar al código de ejemplo, vea Llamada a fragmentos de código de Configuration Manager.

Sub SWDCreateAdvertisement(connection, existingCollectionID, existingPackageID, existingProgramName, newAdvertisementName, newAdvertisementComment, newAdvertisementFlags, newRemoteClientFlags, newAdvertisementStartOfferDateTime, newAdvertisementStartOfferEnabled)  
    Dim newAdvertisement  
    ' Create the new advertisement object.  
    Set newAdvertisement = connection.Get("SMS_Advertisement").SpawnInstance_  

    ' Populate the advertisement properties.  
    newAdvertisement.CollectionID = existingCollectionID  
    newAdvertisement.PackageID = existingPackageID  
    newAdvertisement.ProgramName = existingProgramName  
    newAdvertisement.AdvertisementName = newAdvertisementName  
    newAdvertisement.Comment = newAdvertisementComment  
    newAdvertisement.AdvertFlags = newAdvertisementFlags  
    newAdvertisement.RemoteClientFlags = newRemoteClientFlags
    newAdvertisement.PresentTime = newAdvertisementStartOfferDateTime  
    newAdvertisement.PresentTimeEnabled = newAdvertisementStartOfferEnabled  

    ' Save the new advertisement and properties.  
    newAdvertisement.Put_   

    ' Output new advertisement name.  
    Wscript.Echo "Created advertisement: " & newAdvertisement.AdvertisementName  

End Sub  
public void CreateSWDAdvertisement(WqlConnectionManager connection, string existingCollectionID, string existingPackageID, string existingProgramName, string newAdvertisementName, string newAdvertisementComment, int newAdvertisementFlags, int newRemoteClientFlags, string newAdvertisementStartOfferDateTime, bool newAdvertisementStartOfferEnabled)  
{  
    try  
    {  
        // Create new advertisement instance.  
        IResultObject newAdvertisement = connection.CreateInstance("SMS_Advertisement");  

        // Populate new advertisement values.  
        newAdvertisement["CollectionID"].StringValue = existingCollectionID;  
        newAdvertisement["PackageID"].StringValue = existingPackageID;  
        newAdvertisement["ProgramName"].StringValue = existingProgramName;  
        newAdvertisement["AdvertisementName"].StringValue = newAdvertisementName;  
        newAdvertisement["Comment"].StringValue = newAdvertisementComment;  
        newAdvertisement["AdvertFlags"].IntegerValue = newAdvertisementFlags;  
        newAdvertisement["RemoteClientFlag"].IntegerValue = newRemoteClientFlags;
        newAdvertisement["PresentTime"].StringValue = newAdvertisementStartOfferDateTime;  
        newAdvertisement["PresentTimeEnabled"].BooleanValue = newAdvertisementStartOfferEnabled;  

        // Save the new advertisement and properties.  
        newAdvertisement.Put();  

        // Output new assignment name.  
        Console.WriteLine("Created advertisement: " + newAdvertisement["AdvertisementName"].StringValue);  
    }  

    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to assign advertisement. Error: " + ex.Message);  
        throw;  
    }  
}  

El método de ejemplo tiene los parámetros siguientes:

Parámetro Tipo Descripción
connection

swbemServices
-Administrado: WqlConnectionManager
- VBScript: SWbemServices
Una conexión válida al proveedor de SMS.
existingCollectionID Cadena Identificador de una colección existente con la que asociar el anuncio.
existingPackageID Cadena Identificador de un paquete existente con el que asociar el anuncio.
existingProgramName Cadena Nombre del programa asociado al anuncio.
newAdvertisementName Cadena Nombre del nuevo anuncio.
newAdvertisementComment Cadena Un comentario para el nuevo anuncio.
newAdvertisementFlags Entero Marcas que especifican opciones para el nuevo anuncio.
newRemoteClientFlags Entero Marcas que especifican cómo se debe ejecutar el programa cuando el cliente se conecta local o remotamente a un punto de distribución.
newAdvertisementStartOfferDateTime Cadena La hora en que se ofrece por primera vez el nuevo anuncio.
newAdvertisementStartOfferEnabled Boolean true si se ofrece el anuncio.

Compilar el código

El ejemplo de C# requiere:

Espacios de nombres

  • System

  • Microsoft.ConfigurationManagement.ManagementProvider

  • Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Ensamblado

  • adminui.wqlqueryengine

  • microsoft.configurationmanagement.managementprovider

  • mscorlib

Programación sólida

Para obtener más información sobre el control de errores, vea Acerca de los errores de Configuration Manager.

Vea también