The data discovery record (DDR), in System Center 2012 R2 Configuration Manager, specifies the resource type, the discovery process, the site that discovered the resource, and the resource properties. System Center 2012 R2 Configuration Manager provides six library functions that you use to create your own DDRs. For more information. see About Creating a Data Discovery Record.

To create a data discovery record

  1. Create a new instance of the SMSResGen class.

  2. Create a new DDR by using the NewDDR method.

  3. Add properties to the DDR by using the ADDPROP_ methods.

  4. Write the new DDR to a file by using the DDRWrite method.


The following example creates a DDR.

Visual Basic Script  Copy Code
Sub CreateNewDDR()

	' Define constants.
	Const ADDPROP_NONE  = &H0
	Const ADDPROP_GUID  = &H2
	Const ADDPROP_KEY   = &H8
	' Define variables.
	Dim newDDR
	Dim siteCode
	Dim computerName
	Dim siteName
	Dim newIPAddress(2), newIPSubnet(2), newMACAddress(2)
	' Load variables with values.
	siteCode = "ABC"
	siteName="Active Directory Site Name"

	' Load an instance of the SMSResGen.dll.
	Set newDDR=CreateObject("SMSResGen.SMSResGen.1")

	' Create a new DDR using the DDRNew method.
	newDDR.DDRNew "System", "CustomAgent", siteCode

	' Add properties to the new DDR using the DDRAddString method and the previously defined variables.
	newDDR.DDRAddString "NetBIOS Name", computerName, 64, ADDPROP_KEY
	newDDR.DDRAddString "AD Site Name", siteName, 64, ADDPROP_NONE

	' Add properties to the new DDR using the DDRAddStringArray method and the previously defined variables. 
	newDDR.DDRAddStringArray "IP Addresses", Array(newIPAddress(0),newIPAddress(1)), 64, ADDPROP_ARRAY
	newDDR.DDRAddStringArray "MAC Addresses", Array(newMACAddress(0),newMACAddress(1)), 64, ADDPROP_ARRAY OR ADDPROP_KEY
	newDDR.DDRAddStringArray "IP Subnets", Array(newIPSubnet(0),newIPSubnet(1)), 64, ADDPROP_ARRAY
	' Write new DDR to file.
	newDDR.DDRWrite "NewDDR.DDR"
	wscript.echo "Created new DDR."

End Sub
C#  Copy Code
public void CreateNewDDR()
		// Define and set the required variables. 
		string Computer = "ComputerName";
		string SiteName = "Active Directory Site Name";
		string[] IPAddress  = new string[] { "", "" };
		string[] IPSubnet   = new string[] { "", "" };
		string[] MACAddress = new string[] { "00:02:A5:B1:11:68", "00:02:A5:B1:11:68" };
		string siteCode = "TQ1";

		// Create the SMSResGenClass instance.

		// Create a new DDR using the DDRNew method.
		newDDR.DDRNew("System", "CustomAgent", siteCode);

		// Add properties to the new DDR using the DDRAddString method and the previously defined variables.
		newDDR.DDRAddString("NetBIOS Name", Computer, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_KEY);
		newDDR.DDRAddString("AD Site Name", SiteName, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_NONE);

		// Add properties to the new DDR using the DDRAddStringArray method and the previously defined variables. 
		newDDR.DDRAddStringArray("IP Subnets", IPAddress, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_ARRAY);
		newDDR.DDRAddStringArray("MAC Addresses", MACAddress, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_ARRAY | SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_KEY);
		newDDR.DDRAddStringArray("IP Subnets", IPSubnet, 64, SMSRSGENCTLLib.DDRPropertyFlagsEnum.ADDPROP_ARRAY);

		// Write new DDR to file.
		Console.WriteLine("Created new DDR."); 
	catch (SmsException ex)
		Console.WriteLine("Failed to create DDR. Error: " + ex.Message);

Compiling the Code

This VBScript and C# examples require smsrsgen.dll and smsrsgenctl.dll respectively. Both files are included as a part of the downloadable Configuration Manager SDK (in the “Redistributables” folder). The file smsrsgenctl.dll is a 32-bit dll and must be registered on the system that will run the application. In addition, the application using smsrsgenctl.dll should be compiled as an x86 application.

Robust Programming

For more information about error handling, see About Configuration Manager Errors.


For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also