How to Import a Windows Driver Described by a Txtsetup.oem File into Configuration Manager
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
You can import a Windows driver that is described by a Txtsetup.oem file, in Microsoft System Center Configuration Manager 2007, by using the CreateFromOEM Method in Class SMS_Driver. Configuration Manager 2007 can automatically create definitions for most drivers from just an .inf file. However, when installing mass-storage drivers on pre-Windows Vista operating systems, Configuration Manager also must have some information that is contained in the Txtsetup.oem file. To facilitate this, CreateFromOEM creates SMS_Driver Server WMI Class objects for each .inf file that is referenced in the Txtsetup.oem file. You then have the opportunity to customize the driver properties before saving them.
Note
If a driver manufacturer has provided a Txtsetup.oem file, you should import the driver by using this procedure instead of the .inf files if you plan to deploy Windows 2000, Windows XP, or Windows Server 2003.
To import a Windows driver
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Call the SMS_Driver class CreateFromOEM method to get a collection of management base objects.
For the management base objects create an SMS_Driver object for each driver.
Populate the SMS_Driver object.
Commit the SMS_Driver object.
Example
The following example method creates an SMS_Driver object for a Windows driver by using the supplied path and Txtsetup.oem file name. The example also enables the driver by setting the value of the IsEnabled property to true. The helper function GetDriverName is used to get the name of the driver from the driver package XML.
Note
The path parameter must be supplied as a Universal Naming Convention (UNC) network path, for example, \\localhost\Drivers\VMSCSI\.
In the example, the LocaleID property is hard-coded to English (U.S.). If you need the locale for non-U.S. installations, you can get it from the SMS_Identification Server WMI ClassLocaleID property.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub ImportOemDriver(connection,path,name)
Dim inParams
Dim outParams
Dim driver
Dim driverClass
On Error Resume Next
Set driverClass = connection.Get("SMS_Driver")
Set inParams = driverClass.Methods_("CreateFromOEM").inParameters.SpawnInstance_()
' Set the driver path and INF file.
inParams.Properties_.item("DriverPath") = path
inParams.Properties_.item("OEMFile") = name
' Execute the method.
Set outParams = driverClass.ExecMethod_("CreateFromOEM", inParams)
If Err <> 0 Then
Wscript.Echo "Failed to import driver: " + path +"\" + name
Exit Sub
End If
For Each driver In outParams.Drivers
' Set driver name and enable the driver.
Dim LocalizedSettings
LocalizedSettings = array(0)
Set LocalizedSettings(0) = connection.Get("SMS_CI_LocalizedProperties").SpawnInstance_()
LocalizedSettings(0).Properties_.item("LocaleID") = 1033
LocalizedSettings(0).Properties_.item("DisplayName") = _
GetDriverName(driver.Properties_.item("SDMPackageXML"), "//DisplayName", "Text")
LocalizedSettings(0).Properties_.item("Description") = ""
driver.Properties_.item("LocalizedInformation") = LocalizedSettings
driver.Properties_.item("IsEnabled") = true
driver.Put_
Next
End Sub
Function GetDriverName(xmlContent, nodeName, attributeName)
' Load the XML Document
Dim attrValue
Dim XMLDoc
Dim objNode
Dim displayNameNode
attrValue = ""
Set XMLDoc = CreateObject("Microsoft.XMLDOM")
XMLDoc.async = False
XMLDoc.loadXML(xmlContent)
'Check for a successful load of the XML Document.
If xmlDoc.parseError.errorCode <> 0 Then
WScript.Echo vbcrlf & "Error loading XML Document. Error Code : 0x" & hex(xmldoc.parseerror.errorcode)
WScript.Echo "Reason: " & xmldoc.parseerror.reason
WScript.Echo "Parse Error line " & xmldoc.parseError.line & ", character " & _
xmldoc.parseError.linePos & vbCrLf & xmldoc.parseError.srcText
GetXMLAttributeValue = ""
Else
' Select the node
Set objNode = xmlDoc.SelectSingleNode(nodeName)
If Not objNode Is Nothing Then
' Found the element, now just pick up the Text attribute value
Set displayNameNode = objNode.attributes.getNamedItem(attributeName)
If Not displayNameNode Is Nothing Then
attrValue = displayNameNode.value
Else
WScript.Echo "Attribute not found"
End If
Else
WScript.Echo "Failed to locate " & nodeName & " element."
End If
End If
' Save the results
GetDriverName = attrValue
End Function
public void ImportOemDriver(
WqlConnectionManager connection,
string path,
string name)
{
try
{
Dictionary<string, object> inParams = new Dictionary<string, object>();
// Set up parameters for the path and file name.
inParams.Add("DriverPath", path);
inParams.Add("OEMFile", name);
// Import the INF file.
IResultObject outParams = connection.ExecuteMethod("SMS_Driver", "CreateFromOEM", inParams);
// Create the driver instance from the management base object returned in result["Drivers"].
foreach (object obj in outParams["Drivers"].ObjectArrayValue)
{
IResultObject driver = connection.CreateInstance(obj);
driver["IsEnabled"].BooleanValue = true;
List<IResultObject> driverInformationList = driver.GetArrayItems("LocalizedInformation");
// Set up the display name and other information.
IResultObject driverInfo = connection.CreateEmbeddedObjectInstance("SMS_CI_LocalizedProperties");
driverInfo["DisplayName"].StringValue = GetDriverName(driver);
driverInfo["LocaleID"].IntegerValue = 1033;
driverInfo["Description"].StringValue = "";
driverInformationList.Add(driverInfo);
driver.SetArrayItems("LocalizedInformation", driverInformationList);
// Commit the SMS_Driver object.
driver.Put();
}
}
catch (SmsException e)
{
Console.WriteLine("Failed to import driver: " + e.Message);
throw;
}
}
public string GetDriverName(IResultObject driver)
{
// Extract
XmlDocument sdmpackage = new XmlDocument();
sdmpackage.LoadXml(driver.Properties["SDMPackageXML"].StringValue);
// Iterate over all the <DisplayName/> tags.
foreach (XmlNode displayName in sdmpackage.GetElementsByTagName("DisplayName"))
{
// Grab the first one with a Text attribute not equal to null.
if (displayName != null && displayName.Attributes["Text"] != null
&& !string.IsNullOrEmpty(displayName.Attributes["Text"].Value))
{
// Return the DisplayName text.
return displayName.Attributes["Text"].Value;
}
}
// Default the driverName to the UniqueID.
return driver["CI_UniqueID"].StringValue;
}
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
Connection |
|
A valid connection to the SMS Provider. |
path |
|
A valid UNC network path to the folder that contains the driver contents. For example, \\Servers\Driver\VideoDriver. |
name |
|
The name of the Txtsetup.oem file. For example, you might have \\server\drivers\Video for path and Txtsetup.oem for name. |
Compiling the Code
This C# example requires:
Namespaces
System
System.Collections.Generic
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
Concepts
How to Specify the Supported Platforms for a Driver
Operating System Deployment Driver Management