Creating a Package and Programs Using a PDF Template
PDF templates contain the default values used to create SMS_Package and SMS_Program objects. The package and programs that are created can then be used in the software distribution process.
To use a PDF template to create a package and program
- Call the GetPDFData ** method. This method gets the template data from the PDF store and creates the SMS_Package and SMS_Program objects with the default information.
- Modify the appropriate property values in the newly-created package object, such as supplying the location of the package source files.
- Call the IWbemServices::PutInstance method to store the package in the SMS database.
- Add an IWbemCallResult object to your PutInstance method to get the returned object path for the package. The object path is used to get the PackageID property of your program objects by retrieving PackageID from the object path.
- Repeat steps 2 and 3 for each program object.
The following example shows you how to use GetPDFData to create a package and programs for software distribution.
[C/C++]
This example assumes the IWbemServices and IWbemContext (context qualifiers) objects have been created. For information on connecting to SMS, see Connecting to the SMS Namespace. For information on creating a context object, see SMS Context Qualifiers.
[C/C++] HRESULT CreateProgramAndPackageUsingaPDFTemplate(IWbemServices* &pServices;, _variant_t vPDFIdentifier,IWbemContext* pSMSContext) { HRESULT hr; IWbemClassObject *pclsPDFPackage = NULL; //SMS_PDF_Package class IWbemClassObject *pinstPackage = NULL; //Instance of SMS_Package IWbemClassObject *pinstProgram = NULL; //Instance of SMS_Program IWbemClassObject *pdefInParams = NULL; //Definition of method in parameters IWbemClassObject *pinstInParams = NULL; //Instance of method in parameters IWbemClassObject *pinstOutParams = NULL; //Instance of method out parameters IWbemCallResult *pPkgPath = NULL; //Strip the PackageID from the path _variant_t vTemp; _variant_t vPackage, vPrograms; BSTR bstrPath, bstrPackageID; long LBound, UBound, i; //SafeArray elements try{ //Get the SMS_PDF_Package class definition that contains the GetPDFData method. hr = pServices->GetObject(_bstr_t(L"SMS_PDF_Package"), 0, NULL, &pclsPDFPackage;, 0); //This example generates a test PDF template that you need to supply. //This example assumes you have obtained the PDFID for //the PDF package template from the SMS_PDF_Package class. if (!SUCCEEDED(hr)) throw hr; hr = pclsPDFPackage->GetMethod(_bstr_t(L"GetPDFData"), 0, &pdefInParams;, NULL); pclsPDFPackage->Release(); hr = pdefInParams->SpawnInstance(0, &pinstInParams;); pdefInParams->Release(); if (!SUCCEEDED(hr)) throw hr; hr = pinstInParams->Put(_bstr_t(L"PDFID"), 0, &vPDFIdentifier;, 0); if (!SUCCEEDED(hr)) throw hr; hr = pServices->ExecMethod(_bstr_t(L"SMS_PDF_Package"), _bstr_t(L"GetPDFData"), 0, NULL, pinstInParams, &pinstOutParams;, NULL); pinstInParams->Release(); if (!SUCCEEDED(hr)) throw hr; pinstOutParams->Get(_bstr_t(L"PackageData"), 0, &vPackage;, 0, 0); hr = ((IUnknown *)vPackage)->QueryInterface(IID_IWbemClassObject, (void **)&pinstPackage;); if (!SUCCEEDED(hr)) throw hr; hr = pinstOutParams->Get(_bstr_t(L"ProgramData"), 0, &vPrograms;, 0, 0); pinstOutParams->Release(); if (!SUCCEEDED(hr)) throw hr; //Add the rest of the information to the package. vTemp = (long)2; //STORAGE_DIRECT (2) hr = pinstPackage->Put(L"PkgSourceFlag", 0, &vTemp;, NULL); vTemp = L"C:\\TestPDF\\TestPDFInstall\\Release"; //Path to your source hr = pinstPackage->Put(L"PkgSourcePath", 0, &vTemp;, NULL); //Use the CallResult to get the PackageID for this package. The PackageID //is used in the programs. hr = pServices->PutInstance(pinstPackage, 0, pSMSContext, &pPkgPath;); pinstPackage->Release(); hr = pPkgPath->GetResultString(0, &bstrPath;); bstrPackageID = SysAllocStringLen((wcschr(bstrPath, '\"') + 1), 8); //Loop through the array of programs returned from GetPDFData, //assign the PackageID and put the instance. SafeArrayGetLBound(V_ARRAY(&vPrograms;), 1, &LBound;); SafeArrayGetUBound(V_ARRAY(&vPrograms;), 1, &UBound;); for (i = LBound; i <= UBound; i++) { SafeArrayGetElement(V_ARRAY(&vPrograms;), &i;, &pinstProgram;); vTemp = bstrPackageID; hr = pinstProgram->Put(L"PackageID", 0, &vTemp;, NULL); hr = pServices->PutInstance(pinstProgram, 0, pSMSContext, NULL); if (!SUCCEEDED(hr)) throw hr; pinstProgram->Release(); pinstProgram = NULL; } SysFreeString(bstrPackageID); } catch(...) { if( pclsPDFPackage != NULL) pclsPDFPackage->Release(); if( pinstProgram != NULL) pinstProgram->Release(); if( pdefInParams != NULL) pdefInParams->Release(); if( pinstInParams != NULL) pinstInParams->Release(); if( pinstOutParams != NULL) pinstOutParams->Release(); if( pPkgPath != NULL) pPkgPath->Release(); } return hr; }
[Visual Basic]
This example assumes the SWbemServices and SWbemNamedValueSet (context qualifiers) objects have been created. For information on connecting to SMS, see Connecting to the SMS Namespace. For information on creating a context object, see SMS Context Qualifiers.
[Visual Basic] Dim clsPDFPackage As SWbemObject Dim instPackage As SWbemObject Dim avPrograms() As Variant 'Array of SMS_Program instances Dim vProgram As Variant 'SMS_Program instance Dim instPath As SWbemObjectPath Dim PackageID As String Dim rc As Long 'Return Code 'This example generates a PC Analyzer package and its programs from the PC 'Analyzer PDF template. This example assumes you have obtained the PDFID for 'the PDF package template from the SMS_PDF_Package class. Set clsPDFPackage = Services.Get("SMS_PDF_Package") rc = clsPDFPackage.GetPDFData(PDFID, instPackage, avPrograms) instPackage.PkgSourceFlag = 2 'STORAGE_DIRECT instPackage.PkgSourcePath = "D:\SMS\Y2K\Y2KSCAN" Set instPath = instPackage.Put_(, SMSContext) PackageID = instPath.Keys("PackageID") For Each vProgram In avPrograms vProgram.PackageID = PackageID vProgram.Put_ , SMSContext Next