SCCM Development (Code)

From Slothx.net

Jump to: navigation, search

Contents

Development

using System.Management;
using Microsoft.ConfigurationManagement;
using Microsoft.ConfigurationManagement.ManagementProvider;
using Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine;


AdminUI.WqlQueryEngine C:\Program Files (x86)\Microsoft Configuration Manager\AdminUI\bin\adminui.wqlqueryengine.dll
Microsoft.ConfigurationManagement C:\Program Files (x86)\Microsoft Configuration Manager\AdminUI\bin\microsoft.configurationmanagement.dll
Microsoft.ConfigurationManagement.ManagementProvider C:\Program Files (x86)\Microsoft Configuration Manager\AdminUI\bin\microsoft.configurationmanagement.managementprovider.dll

Code to Check

Development Load Package


// How to Create a Package by Using a Package Definition File Template
// http://msdn.microsoft.com/en-us/library/cc143469.aspx

Sub SWDCreatePDFPackage(connection, existingPDF_ID, newPackageSourceFlag, newPackageSourcePath)

    ' The PDF_ID must be passed in.
    ' The PDF_ID can be identified through the SMS_PDF_Package class.

    ' Package Creation
    ' ----------------     
    ' Create new SMS_PDF_Package instance.
    Set newPDFPackage = connection.Get("SMS_PDF_Package")
    
    ' Load the Package Definition File data using the GetPDFData method.
    returnCode = newPDFPackage.GetPDFData(existingPDF_ID, newPackage, arrayOfPrograms)

    ' Assign any additional package properties.
    newPackage.PkgSourceFlag = newPackageSourceFlag
    newPackage.PkgSourcePath = newPackageSourcePath
    
    ' Save the package path and get the Package ID.
    Set newPackagePath = newPackage.Put_
    packageID = newPackagePath.Keys("PackageID")

    ' Program Creation 
    ' -----------------    
    ' Enumerate through the program array and create the programs.
    For Each program In arrayOfPrograms
        program.PackageID = packageID
        program.Put_
    Next

End Sub

// LoadPDF Method in Class SMS_PDF_Package
// http://msdn.microsoft.com/en-us/library/cc144746.aspx

    Const ForReading = 1
   
    Dim fs, f                         ' File system object and file object.
    Dim clsPDF As SWbemObject         ' SMS_PDF_Package class definition.
    Dim ReturnCode As Long            ' Return code value from LoadPDF method.
    Dim PDFID As Long                 ' Package definition file identifier generated from LoadPDF.
    Dim PDFContent As String          ' Package definition file file content.
    Dim ReqIconNames() As Variant     ' Required icon names from LoadPDF.
    Dim Icon() As Byte                ' Icon used as input to LoadIconForPDF method.
    Dim i, j As Integer
    Dim FileSize As Integer           ' Size of the icon file.
    
    
    Set Services = GetObject("winmgmts:\root\sms\<sitecode>")
    
    ' Open the package definition file file and read the content into a string.
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile(<path\filename>, ForReading)
    PDFContent = f.ReadAll
    f.Close
    
    ' Load the package definition file into the package definition file store. Use the PDFID and ReqIconNames 
    ' Variables in the LoadIconForPDF method.
    Set clsPDF = Services.Get("SMS_PDF_Package")
    ReturnCode = clsPDF.LoadPDF(<path\filename>, _
                                PDFContent, _
                                PDFID, _
                                ReqIconNames)
                                
    ' You must load all the icons for the package definition file if the package definition file contains icons.
    For i = LBound(ReqIconNames) To UBound(ReqIconNames)
        Open <path> & ReqIconNames(i) For Binary Access Read As #1
        FileSize = LOF(1) - 1
        ReDim Icon(FileSize)
        For j = 0 To FileSize
            Get #1, , Icon(j)
        Next
        Close #1
        
        clsPDF.LoadIconForPDF PDFID, ReqIconNames(i), Icon
    Next


Install SCCM package SMS_PDF_Package

Site Changes

Create PDF Package

 public void CreatePackage()
        {
            string sms_namespace = "\\\\sccm1\\root\\sms\\site_s01";
            string sms_filename = "c:\\ward\\0010003A - TimeZone.sms";

            object[] inoutparameter = new object[4]; //call-param for LoadPDF
            object[] objGetPDFDataOutParameter = new object[3]; // call-parameter for GetPDFData

            // Step 1: Put PDF-file into the PDF-store of SMS

            ManagementClass package1 = new ManagementClass(sms_namespace, "SMS_PDF_Package", null);
            StreamReader PDFreader = new StreamReader(sms_filename);
            string PDFcontent = PDFreader.ReadToEnd();
            PDFreader.Close();

            inoutparameter[0] = sms_filename;
            inoutparameter[1] = PDFcontent;
            //inoutparameter[2] output parameter of Typ int contains the PDF ID assinged by SMS
            //inoutparameter[3] = output parameter vom Typ string-array ist

            object objRet = package1.InvokeMethod("LoadPDF", inoutparameter);


            // Step2: Retrieve the Package defined in the PDF-file out of the SMS PDF-store (SMS_Package object)

            ManagementClass newpackage = new ManagementClass
            (sms_namespace, "SMS_PDF_Package", null);

            // objGetPDFDataOutParameter[1] contains SMS_Package Objekt
            // objGetPDFDataOutParameter [2] contains the array of SMS_Program 
            // objects specified in the PDF-file

            objGetPDFDataOutParameter[0] = (uint)inoutparameter[2];
            Object objRet2 = newpackage.InvokeMethod("GetPDFData", objGetPDFDataOutParameter);

            string objekttype = objGetPDFDataOutParameter[1].GetType().ToString();
            newpackage["Description"] = "Test Package 1";
            newpackage.Put();

            // shows that GetPDFData returns a System.Management.ManagementBaseObject

Site Navigation

Personal tools