How to Read a Configuration Manager Site Control File Embedded Property
Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2
In Microsoft System Center Configuration Manager 2007, you read an embedded property from a site control file resource by getting the SMS_EmbeddedProperty object for the embedded object from the resources Props property array.
An embedded property has the following properties that you can read. For more information, see SMS_EmbeddedProperty.
Value | Description |
---|---|
PropertyName |
The embedded property name. |
Value |
An integer value. |
Value1 |
A string value. |
Value2 |
A string value. |
To read a site control file embedded property.
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Using the connection object from step one, get a site control file resource. For more information, see About the Configuration Manager Site Control File.
Get the SMS_EmbeddedProperty for the required embedded property.
Example
The following example method populates the supplied value, value1 and value2 parameters with the values of the embedded property identified by the propertyName parameter. true is returned if the embedded property is found; otherwise, false is returned.
You can update the embedded property returned from this method by using the method in How to Write a Configuration Manager Site Control File Embedded Property.
To view code that calls these methods, see How to Read and Write to the Configuration Manager Site Control File by Using Managed Code.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Function GetScfProperty(resource, _
propertyName, _
ByRef value, _
ByRef value1, _
ByRef value2)
Dim scfProperty
For Each scfProperty in resource.Props
if scfProperty.PropertyName = propertyName Then
' Found the property, so populate values and exit.
value = scfProperty.Value
value1 = scfProperty.Value1
value2 = scfProperty.Value2
GetScfProperty = true
Exit Function
End If
Next
' Did not find the property.
GetScfProperty = false
End Function
public bool GetScfEmbeddedProperty(
IResultObject resource,
string propertyName,
ref int value,
ref string value1,
ref string value2)
{
value = 0;
value1 = "";
value2 = "";
try
{
// Find the property.
if (resource.EmbeddedProperties.ContainsKey(propertyName))
{
value = resource.EmbeddedProperties[propertyName]["Value"].IntegerValue;
value1 = resource.EmbeddedProperties[propertyName]["Value1"].StringValue;
value2 = resource.EmbeddedProperties[propertyName]["Value2"].StringValue;
return true;
}
}
catch(SmsException e)
{
Console.WriteLine("Error: " + e.Message);
}
// Either the property or property array does not exist.
return false;
}
The example method has the following parameters:
Parameter |
Type |
Description |
Resource |
|
The site control file resource that contains the embedded property. For more information, see How to Read and Write to the Configuration Manager Site Control File by Using Managed Code. |
propertyName |
|
The embedded property to be written to. |
Value |
|
The SMS_EmbeddedProperty class value property value. |
Value1 |
|
The SMS_EmbeddedProperty class value1 property value. |
Value2 |
|
The SMS_EmbeddedProperty class value2 property value. |
Compiling the Code
The C# example has the following compilation requirements:
Namespaces
System
System.Collections.Generic
System.Collections
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
Security
For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.
See Also
Tasks
How to Write a Configuration Manager Site Control File Embedded Property
How to Write a Configuration Manager Site Control File Embedded Property List
Concepts
About the Configuration Manager Site Control File
How to Read a Configuration Manager Site Control File Embedded Property List
How to Read a Configuration Manager Site Control File Embedded RegMultiString List
How to Write a Configuration Manager Site Control File Embedded RegMultiString List
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI