In System Center 2012 Configuration Manager, you can report user-defined informational, warning, and error status messages, on the site server, by using the following methods that are defined in the SMS_StatusMessage class:

Method Description

RaiseErrorStatusMsg

Raises an error status message.

RaiseWarningStatusMsg

Raises a warning status message.

RaiseInformationalStatusMsg

Raises an informational status message.

To report a user defined status message by using WMI

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Call the SMS_StatusMessage class method that is appropriate for the type of status message you want to raise.

Example

The following example raises an error message. It also defines an attribute identifier and attribute values for a package. For more information about attributes, see SMS_StatMsgAttributes Server WMI Class.

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.

Visual Basic Script  Copy Code
Sub RaiseErrorStatusMessage(connection)

	Dim smsContext
	Dim statusMessageParameters
	Dim inParams
	Dim statusMessageClass
	 

	Set smsContext = CreateObject("WbemScripting.SWbemNamedValueSet")

	' Add the context qualifiers to the set.
	smsContext.Add "LocaleID", "MS\1033"
	smsContext.Add "MachineName", "MyComputerName"
	smsContext.Add "ApplicationName", "MyApplication"
   
   ' Obtain the class definition object of a SMS_Status Message object.
	Set statusMessageClass = connection.Get("SMS_StatusMessage")
   
	' Set up the in parameter.
	Set inParams = statusMessageClass.Methods_("RaiseErrorStatusMsg").InParameters.SpawnInstance_
	inParams.MessageText = "This is an error message"
	inParams.MessageType = 768
	inParams.AttrIDs = Array(400)
	inParams.AttrValues = Array("MyPackageID")

	Call connection.ExecMethod( "SMS_StatusMessage", "RaiseErrorStatusMsg", inParams,,smsContext)
	If Err.Number<>0 Then
		Wscript.Echo "Couldn't run method"
		Exit Sub
	End If
 
 End Sub
C#  Copy Code
public void RaiseErrorStatusMessage(WqlConnectionManager connection)
{
	try
	{
		Dictionary<string, object> StatusMessageParameters = new Dictionary<string, object>();

		connection.Context.Add("ApplicationName", "MyApplication");
		connection.Context.Add("MachineName", "MyComputerName");
		connection.Context.Add("LocaleID", @"MS\1033");


		// Add the parameters.
		StatusMessageParameters.Add("MessageText", "This is an error message");
		StatusMessageParameters.Add("MessageType", 768);
		StatusMessageParameters.Add("AttrIDs", new int[] { 400 });
		StatusMessageParameters.Add("AttrValues", new string[] { "MyPackageID" });

		// Call the method.
		connection.ExecuteMethod("SMS_StatusMessage", "RaiseErrorStatusMsg", StatusMessageParameters);

}
	catch (SmsException ex)
	{
		Console.WriteLine("Failed to raise error status message: ", ex.Message);
		throw;
}
}

The example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

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

Security

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

See Also