Share via


Creating a Distribution Point

You only need to define a distribution point for a package if the package contains source files (PkgSourcePath). The package is not advertised until the program source files have been propagated to a distribution point share. You can use the default distribution point share or you can specify a share to use. You can specify more than one distribution point to use to distribute your package's source files.

The following example shows you how to assign a distribution point (SMS_DistributionPoint) for a package. This example continues the example started in Creating a Package and Programs Using SMS Classes.

[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 AssigningADistributionPoint(IWbemServices* &pServices;,IWbemContext* pSMSContext, _bstr_t bstrPackageId)
{
HRESULT hr;
_variant_t vTemp;
IWbemClassObject      *pclsDistPoint = NULL;     //SMS_DistributionPoint class
IWbemClassObject      *pinstDistPoint = NULL;    //and instance
IWbemClassObject      *pinstResource = NULL;     //Contains the NALPath
IEnumWbemClassObject  *penumResourceList= NULL;  //Enumeration from query
IWbemClassObject *pinstSite = NULL;				//Site data
unsigned long          ulReturned;
char                  *pszQuery = "SELECT * FROM SMS_SystemResourceList "
                                       "WHERE RoleName = \"SMS Distribution Point\" "
                                       "AND SiteCode = \"YOURSITECODE\""
                                       "AND ServerName = \"YOURSERVERNAME\"";


try {

	

	hr = pServices->GetObject(_bstr_t(L"SMS_DistributionPoint"), 0,
                              NULL, &pclsDistPoint;, 0);
	
	if (!SUCCEEDED(hr))
		throw hr;

	hr = pclsDistPoint->SpawnInstance(0, &pinstDistPoint;);
	pclsDistPoint->Release();
	pclsDistPoint=NULL;

	
	if (!SUCCEEDED(hr))
		throw hr;

	//Associates the package with a distribution point.
	vTemp = bstrPackageId;
	hr = pinstDistPoint->Put(L"PackageID", 0, &vTemp;, NULL);

	if (!SUCCEEDED(hr))
		throw hr;

	//Get the ServerNALPath value for the distribution point from
	//SMS_SystemResourceList. This example gets the distribution
	//point for a specific site and server - only one instance is
   	//returned. If you want to distribute to all distribution points
   	//for a site, remove ServerName from the WHERE clause and add a loop
   	//construct to handle the multiple instances returned from the query.
   	hr = pServices->ExecQuery(_bstr_t(L"WQL"), _bstr_t(pszQuery),
                              WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
                              NULL, &penumResourceList;);

	if (!SUCCEEDED(hr))
		throw hr;

   	hr = CoSetProxyBlanket(penumResourceList,
                           RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
                           RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE,
                           NULL, EOAC_NONE);

	if (!SUCCEEDED(hr))
		throw hr;

	
   	hr = penumResourceList->Next(WBEM_INFINITE, 1, &pinstResource;, &ulReturned;);
	if (!SUCCEEDED(hr))
		throw;

   	hr = pinstResource->Get(L"NALPath", 0, &vTemp;, NULL, NULL);
	if (!SUCCEEDED(hr))
		throw hr;

   	hr = pinstDistPoint->Put(L"ServerNALPath", 0, &vTemp;, NULL);
	if (!SUCCEEDED(hr))
		throw hr;

   	hr = pinstResource->Get(L"SiteCode", 0, &vTemp;, NULL, NULL);
	if (!SUCCEEDED(hr))
		throw hr;
   	hr = pinstDistPoint->Put(L"SiteCode", 0, &vTemp;, NULL);
	if (!SUCCEEDED(hr))
		throw hr;

   	penumResourceList->Release();
   	pinstResource->Release();

	penumResourceList=NULL;
	pinstResource=NULL;

	
   	// Get the SiteName of the site
   	hr = pServices->GetObject(_bstr_t(L"SMS_Site.SiteCode=\"YOURSITECODEHERE\""), WBEM_FLAG_RETURN_WBEM_COMPLETE, NULL, &pinstSite;, NULL);
	if (!SUCCEEDED(hr))
		throw hr;

   	hr = pinstSite->Get(L"SiteName", 0, &vTemp;, NULL, NULL);
	if (!SUCCEEDED(hr))
		throw hr;

	hr = pinstDistPoint->Put(L"SiteName", 0, &vTemp;, NULL);

	
	if (!SUCCEEDED(hr))
		throw hr;
	
	pinstSite->Release();
	pinstSite=NULL;
	
   	hr = pServices->PutInstance(pinstDistPoint, 0, pSMSContext, NULL);
   	if (!SUCCEEDED(hr))
		throw hr;
	
	pinstDistPoint->Release();
	pinstDistPoint=NULL;

}
	
		
catch (...)
{
		if (pclsDistPoint!=NULL)
			pclsDistPoint->Release();
		if (pinstResource != NULL)
			pinstResource->Release();
		if (penumResourceList!=NULL)
       	   	penumResourceList->Release();
		if (pinstSite!=NULL)
			pinstSite->Release();
		if (pinstDistPoint!=NULL)
			pinstDistPoint->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 instDistPoint As SWbemObject        'SMS_DistributionPoint instance
    Dim NALPath As String
    Dim instResources As SWbemObjectSet      'NAL paths to the distribution points
    Dim instResource As SWbemObject          'are in SMS_SystemResourceList
    Dim instSite As SWbemObject              'SMS_Site instance
    Dim Query As String

    Set instDistPoint = Services.Get("SMS_DistributionPoint").SpawnInstance_

    'Associates the package with a distribution point.
    instDistPoint.PackageID = PackageID

    'Query SMS_SystemResourceList for the distribution points defined for your SMS
    'system. Your system can have more than one distribution point defined for a site.
    'This query selects a single distribution point based on the given SiteCode
    'and ServerName.
    Query = "SELECT * FROM SMS_SystemResourceList " & _
            "WHERE RoleName=""SMS Distribution Point"" & _
            "AND SiteCode=""<sitecode>""" & _
            "AND ServerName=""<servername>"""

    Set instResources = Services.ExecQuery(Query, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)

    'Query returns only one instance.
    For Each instResource In instResources
        instDistPoint.ServerNALPath = instResource.NALPath
        instDistPoint.SiteCode = instResource.SiteCode

        Set instSite = Services.Get("SMS_Site.SiteCode="" & instResource.SiteCode & """")
        instDistPoint.SiteName = instSite.SiteName
    Next

    'Create the distribution point instance for the package.
    instDistPoint.Put_ , SMSContext