This documentation is archived and is not being maintained.

ManagementTaskAttribute Class

The ManagementTask attribute indicates that the target method implements a WMI method.

Namespace:  System.Management.Instrumentation
Assembly:  System.Core (in System.Core.dll)

[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = false)]
[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class ManagementTaskAttribute : ManagementMemberAttribute


The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

By default, the WMI method name will be the name of the target method. The parent class of this attribute, ManagementMemberAttribute, includes a Name parameter. You can use that parameter to change the name of the method that is exposed through WMI without changing your internal method name.

The method must be public and it may be static. It can include any combination of [in], [out], [in/out], array or object reference parameters. Array parameters cannot be multidimensional or jagged because of limitations imposed by WMI.

The return type of the method can be: void, scalar, string, datetime or object. It cannot be an array.

The following example shows how to mark a method with the ManagementTask attribute to expose the method to WMI. The method will show up in WMI as ResetCounters.


// Use the ManagementTask attribute to specify that a method
// is exposed to WMI through this provider. Consumers will be
// able to execute this method through WMI.
public void ResetCounters()



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5