Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Wmi / managed / System / Management / ManagementException.cs / 1305376 / ManagementException.cs
using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Serialization; using WbemClient_v1; using System.Security.Permissions; namespace System.Management { ////// public enum ManagementStatus { ///Represents the enumeration of all WMI error codes that are currently defined. ////// The operation was successful. /// NoError = 0, ////// False = 1, ///This value is returned when no more objects /// are available, the number of objects returned is less than the number requested, /// or at the end of an enumeration. It is also returned when the method is called /// with a value of 0 for the ///parameter. /// ResetToDefault = 0x40002, ///An overridden property was deleted. This value is /// returned to signal that the original, non-overridden value has been restored as a /// result of the deletion. ////// Different = 0x40003, ///The compared items (such as objects and classes) /// are not identical. ////// Timedout = 0x40004, ///A call timed out. This is not an /// error condition; therefore, some results may have been returned. ////// NoMoreData = 0x40005, ///No more data is available from the enumeration; the /// user should terminate the enumeration. ////// OperationCanceled = 0x40006, ///The operation was /// canceled. ////// Pending = 0x40007, ///A request is still in progress; however, the results are not /// yet available. ////// DuplicateObjects = 0x40008, ///More than one copy of the same object was detected in /// the result set of an enumeration. ////// PartialResults = 0x40010, ///The user did not receive all of the requested objects /// because of inaccessible resources (other than security violations). ////// Failed = unchecked((int)0x80041001), ///The call failed. ////// NotFound = unchecked((int)0x80041002), ///The object could not be found. ////// The current user does not have permission to perform the /// action. /// AccessDenied = unchecked((int)0x80041003), ////// ProviderFailure = unchecked((int)0x80041004), ///The provider failed after /// initialization. ////// A type mismatch occurred. /// TypeMismatch = unchecked((int)0x80041005), ////// There was not enough memory for the operation. /// OutOfMemory = unchecked((int)0x80041006), ////// InvalidContext = unchecked((int)0x80041007), ///The context object is not valid. ////// InvalidParameter = unchecked((int)0x80041008), ///One of the parameters to the call is not correct. /// ////// NotAvailable = unchecked((int)0x80041009), ///The resource, typically a remote server, is not /// currently available. ////// CriticalError = unchecked((int)0x8004100A), ///An internal, critical, and unexpected error occurred. /// Report this error to Microsoft Product Support Services. ////// InvalidStream = unchecked((int)0x8004100B), ///One or more network packets were corrupted during a remote session. ////// NotSupported = unchecked((int)0x8004100C), ///The feature or operation is not supported. ////// The specified base class is not valid. /// InvalidSuperclass = unchecked((int)0x8004100D), ////// InvalidNamespace = unchecked((int)0x8004100E), ///The specified namespace could not be found. ////// The specified instance is not valid. /// InvalidObject = unchecked((int)0x8004100F), ////// The specified class is not valid. /// InvalidClass = unchecked((int)0x80041010), ////// A provider referenced in the schema does not have a /// corresponding registration. /// ProviderNotFound = unchecked((int)0x80041011), ////// A provider referenced in the schema has an incorrect or /// incomplete registration. /// InvalidProviderRegistration = unchecked((int)0x80041012), ////// COM cannot locate a provider referenced in the schema. /// ProviderLoadFailure = unchecked((int)0x80041013), ////// A component, such as a provider, failed to initialize for internal reasons. /// InitializationFailure = unchecked((int)0x80041014), ////// A networking error that prevents normal operation has /// occurred. /// TransportFailure = unchecked((int)0x80041015), ////// InvalidOperation = unchecked((int)0x80041016), ///The requested operation is not valid. This error usually /// applies to invalid attempts to delete classes or properties. ////// The query was not syntactically valid. /// InvalidQuery = unchecked((int)0x80041017), ////// InvalidQueryType = unchecked((int)0x80041018), ///The requested query language is not supported. ////// AlreadyExists = unchecked((int)0x80041019), ///In a put operation, the ////// flag was specified, but the instance already exists. /// OverrideNotAllowed = unchecked((int)0x8004101A), ///The add operation cannot be performed on the qualifier /// because the owning object does not permit overrides. ////// PropagatedQualifier = unchecked((int)0x8004101B), ///The user attempted to delete a qualifier that was not /// owned. The qualifier was inherited from a parent class. ////// PropagatedProperty = unchecked((int)0x8004101C), ///The user attempted to delete a property that was not /// owned. The property was inherited from a parent class. ////// The client made an unexpected and illegal sequence of /// calls. /// Unexpected = unchecked((int)0x8004101D), ////// IllegalOperation = unchecked((int)0x8004101E), ///The user requested an illegal operation, such as /// spawning a class from an instance. ////// CannotBeKey = unchecked((int)0x8004101F), ///There was an illegal attempt to specify a key qualifier /// on a property that cannot be a key. The keys are specified in the class /// definition for an object and cannot be altered on a per-instance basis. ////// IncompleteClass = unchecked((int)0x80041020), ///The current object is not a valid class definition. /// Either it is incomplete, or it has not been registered with WMI using /// ///(). /// Reserved for future use. /// InvalidSyntax = unchecked((int)0x80041021), ////// Reserved for future use. /// NondecoratedObject = unchecked((int)0x80041022), ////// ReadOnly = unchecked((int)0x80041023), ///The property that you are attempting to modify is read-only. ////// ProviderNotCapable = unchecked((int)0x80041024), ///The provider cannot perform the requested operation, such /// as requesting a query that is too complex, retrieving an instance, creating or /// updating a class, deleting a class, or enumerating a class. ////// ClassHasChildren = unchecked((int)0x80041025), ///An attempt was made to make a change that would /// invalidate a derived class. ////// ClassHasInstances = unchecked((int)0x80041026), ///An attempt has been made to delete or modify a class that /// has instances. ////// Reserved for future use. /// QueryNotImplemented = unchecked((int)0x80041027), ////// IllegalNull = unchecked((int)0x80041028), ///A value of null was specified for a property that may /// not be null, such as one that is marked by a ///, , or /// qualifier. /// InvalidQualifierType = unchecked((int)0x80041029), ///The value provided for a qualifier was not a /// legal qualifier type. ////// The CIM type specified for a property is not valid. /// InvalidPropertyType = unchecked((int)0x8004102A), ////// ValueOutOfRange = unchecked((int)0x8004102B), ///The request was made with an out-of-range value, or is /// incompatible with the type. ////// CannotBeSingleton = unchecked((int)0x8004102C), ///An illegal attempt was made to make a class singleton, /// such as when the class is derived from a non-singleton class. ////// The CIM type specified is not valid. /// InvalidCimType = unchecked((int)0x8004102D), ////// The requested method is not available. /// InvalidMethod = unchecked((int)0x8004102E), ////// InvalidMethodParameters = unchecked((int)0x8004102F), ///The parameters provided for the method are not valid. /// ////// There was an attempt to get qualifiers on a system /// property. /// SystemProperty = unchecked((int)0x80041030), ////// The property type is not recognized. /// InvalidProperty = unchecked((int)0x80041031), ////// CallCanceled = unchecked((int)0x80041032), ///An asynchronous process has been canceled internally or /// by the user. Note that because of the timing and nature of the asynchronous /// operation, the operation may not have been truly canceled. ////// ShuttingDown = unchecked((int)0x80041033), ///The user has requested an operation while WMI is in the /// process of quitting. ////// PropagatedMethod = unchecked((int)0x80041034), ///An attempt was made to reuse an existing method name from /// a base class, and the signatures did not match. ////// UnsupportedParameter = unchecked((int)0x80041035), ///One or more parameter values, such as a query text, is /// too complex or unsupported. WMI is requested to retry the operation /// with simpler parameters. ////// A parameter was missing from the method call. /// MissingParameterID = unchecked((int)0x80041036), ////// A method parameter has an invalid InvalidParameterID = unchecked((int)0x80041037), ///qualifier. /// /// NonconsecutiveParameterIDs = unchecked((int)0x80041038), ///One or more of the method parameters have ////// qualifiers that are out of sequence. /// ParameterIDOnRetval = unchecked((int)0x80041039), ///The return value for a method has an ///qualifier. /// /// The specified object path was invalid. /// InvalidObjectPath = unchecked((int)0x8004103A), ////// OutOfDiskSpace = unchecked((int)0x8004103B), ///There is not enough free disk space to continue the /// operation. ////// BufferTooSmall = unchecked((int)0x8004103C), ///The supplied buffer was too small to hold all the objects /// in the enumerator or to read a string property. ////// The provider does not support the requested put /// operation. /// UnsupportedPutExtension = unchecked((int)0x8004103D), ////// UnknownObjectType = unchecked((int)0x8004103E), ///An object with an incorrect type or version was /// encountered during marshaling. ////// UnknownPacketType = unchecked((int)0x8004103F), ///A packet with an incorrect type or version was /// encountered during marshaling. ////// The packet has an unsupported version. /// MarshalVersionMismatch = unchecked((int)0x80041040), ////// MarshalInvalidSignature = unchecked((int)0x80041041), ///The packet is corrupted. ////// An attempt has been made to mismatch qualifiers, such as /// putting [key] on an object instead of a property. /// InvalidQualifier = unchecked((int)0x80041042), ////// A duplicate parameter has been declared in a CIM method. /// InvalidDuplicateParameter = unchecked((int)0x80041043), ////// TooMuchData = unchecked((int)0x80041044), ///Reserved for future use. ////// ServerTooBusy = unchecked((int)0x80041045), ///The delivery of an event has failed. The provider may /// choose to re-raise the event. ////// The specified flavor was invalid. /// InvalidFlavor = unchecked((int)0x80041046), ////// CircularReference = unchecked((int)0x80041047), ///An attempt has been made to create a reference that is /// circular (for example, deriving a class from itself). ////// The specified class is not supported. /// UnsupportedClassUpdate = unchecked((int)0x80041048), ////// CannotChangeKeyInheritance = unchecked((int)0x80041049), ///An attempt was made to change a key when instances or derived /// classes are already using the key. ////// CannotChangeIndexInheritance = unchecked((int)0x80041050), ///An attempt was made to change an index when instances or derived /// classes are already using the index. ////// TooManyProperties = unchecked((int)0x80041051), ///An attempt was made to create more properties than the /// current version of the class supports. ////// UpdateTypeMismatch = unchecked((int)0x80041052), ///A property was redefined with a conflicting type in a /// derived class. ////// UpdateOverrideNotAllowed = unchecked((int)0x80041053), ///An attempt was made in a derived class to override a /// non-overrideable qualifier. ////// UpdatePropagatedMethod = unchecked((int)0x80041054), ///A method was redeclared with a conflicting signature in a /// derived class. ////// An attempt was made to execute a method not marked with /// [implemented] in any relevant class. /// MethodNotImplemented = unchecked((int)0x80041055), ////// MethodDisabled = unchecked((int)0x80041056), ///An attempt was made to execute a method marked with /// [disabled]. ////// RefresherBusy = unchecked((int)0x80041057), ///The refresher is busy with another operation. ////// UnparsableQuery = unchecked((int)0x80041058), ///The filtering query is syntactically invalid. ////// The FROM clause of a filtering query references a class /// that is not an event class. /// NotEventClass = unchecked((int)0x80041059), ////// A GROUP BY clause was used without the corresponding /// GROUP WITHIN clause. /// MissingGroupWithin = unchecked((int)0x8004105A), ////// A GROUP BY clause was used. Aggregation on all properties /// is not supported. /// MissingAggregationList = unchecked((int)0x8004105B), ////// PropertyNotAnObject = unchecked((int)0x8004105C), ///Dot notation was used on a property that is not an /// embedded object. ////// A GROUP BY clause references a property that is an /// embedded object without using dot notation. /// AggregatingByObject = unchecked((int)0x8004105D), ////// An event provider registration query /// ( UninterpretableProviderQuery = unchecked((int)0x8004105F), ///) did not specify the classes for which /// events were provided. /// /// BackupRestoreWinmgmtRunning = unchecked((int)0x80041060), ///An request was made to back up or restore the repository /// while WinMgmt.exe was using it. ////// QueueOverflow = unchecked((int)0x80041061), ///The asynchronous delivery queue overflowed from the /// event consumer being too slow. ////// The operation failed because the client did not have the /// necessary security privilege. /// PrivilegeNotHeld = unchecked((int)0x80041062), ////// InvalidOperator = unchecked((int)0x80041063), ///The operator is not valid for this property type. ////// LocalCredentials = unchecked((int)0x80041064), ///The user specified a username, password, or authority on a /// local connection. The user must use an empty user name and password and rely on /// default security. ////// CannotBeAbstract = unchecked((int)0x80041065), ///The class was made abstract when its base class is not /// abstract. ////// AmendedObject = unchecked((int)0x80041066), ///An amended object was used in a put operation without the /// WBEM_FLAG_USE_AMENDED_QUALIFIERS flag being specified. ////// The client was not retrieving objects quickly enough from /// an enumeration. /// ClientTooSlow = unchecked((int)0x80041067), ////// RegistrationTooBroad = unchecked((int)0x80042001), ///The provider registration overlaps with the system event /// domain. ////// RegistrationTooPrecise = unchecked((int)0x80042002) } ///A WITHIN clause was not used in this query. ////// ///Represents management exceptions. ////// [Serializable] public class ManagementException : SystemException { private ManagementBaseObject errorObject = null; private ManagementStatus errorCode = 0; internal static void ThrowWithExtendedInfo(ManagementStatus errorCode) { ManagementBaseObject errObj = null; string msg = null; //Try to get extended error info first, and save in errorObject member IWbemClassObjectFreeThreaded obj = WbemErrorInfo.GetErrorInfo(); if (obj != null) errObj = new ManagementBaseObject(obj); //If the error code is not a WMI one and there's an extended error object available, stick the message //from the extended error object in. if (((msg = GetMessage(errorCode)) == null) && (errObj != null)) try { msg = (string)errObj["Description"]; } catch {} throw new ManagementException(errorCode, msg, errObj); } internal static void ThrowWithExtendedInfo(Exception e) { ManagementBaseObject errObj = null; string msg = null; //Try to get extended error info first, and save in errorObject member IWbemClassObjectFreeThreaded obj = WbemErrorInfo.GetErrorInfo(); if (obj != null) errObj = new ManagementBaseObject(obj); //If the error code is not a WMI one and there's an extended error object available, stick the message //from the extended error object in. if (((msg = GetMessage(e)) == null) && (errObj != null)) try { msg = (string)errObj["Description"]; } catch {} throw new ManagementException(e, msg, errObj); } internal ManagementException(ManagementStatus errorCode, string msg, ManagementBaseObject errObj) : base (msg) { this.errorCode = errorCode; this.errorObject = errObj; } internal ManagementException(Exception e, string msg, ManagementBaseObject errObj) : base (msg, e) { try { if (e is ManagementException) { errorCode = ((ManagementException)e).ErrorCode; // May/may not have extended error info. // if (errorObject != null) errorObject = (ManagementBaseObject)((ManagementException)e).errorObject.Clone(); else errorObject = null; } else if (e is COMException) errorCode = (ManagementStatus)((COMException)e).ErrorCode; else errorCode = (ManagementStatus)this.HResult; } catch {} } ///using System; /// using System.Management; /// /// // This sample demonstrates how to display error /// // information stored in a ManagementException object. /// class Sample_ManagementException /// { /// public static int Main(string[] args) /// { /// try /// { /// ManagementObject disk = /// new ManagementObject("Win32_LogicalDisk.DeviceID='BAD:'"); /// disk.Get(); // throws ManagementException /// Console.WriteLine("This shouldn't be displayed."); /// } /// catch (ManagementException e) /// { /// Console.WriteLine("ErrorCode " + e.ErrorCode); /// Console.WriteLine("Message " + e.Message); /// Console.WriteLine("Source " + e.Source); /// if (e.ErrorInformation) //extended error object /// Console.WriteLine("Extended Description : " + e.ErrorInformation["Description"]); /// } /// return 0; /// } /// } ///
///Imports System /// Imports System.Management /// /// ' This sample demonstrates how to display error /// ' information stored in a ManagementException object. /// Class Sample_ManagementException /// Overloads Public Shared Function Main(args() As String) As Integer /// Try /// Dim disk As New ManagementObject("Win32_LogicalDisk.DeviceID='BAD:'") /// disk.Get() ' throws ManagementException /// Console.WriteLine("This shouldn't be displayed.") /// Catch e As ManagementException /// Console.WriteLine("ErrorCode " & e.ErrorCode) /// Console.WriteLine("Message " & e.Message) /// Console.WriteLine("Source " & e.Source) /// If e.ErrorInformation != Nothing Then 'extended error object /// Console.WriteLine("Extended Description : " & e.ErrorInformation("Description")) /// End If /// End Try /// Return 0 /// End Function /// End Class ///
////// /// TheInitializes a new instance of the ///class that is serializable. to populate with data. /// The destination (see ) for this serialization. protected ManagementException(SerializationInfo info, StreamingContext context) : base(info, context) { errorCode = (ManagementStatus)info.GetValue("errorCode", typeof(ManagementStatus)); errorObject = info.GetValue("errorObject", typeof(ManagementBaseObject)) as ManagementBaseObject; } /// /// public ManagementException():this(ManagementStatus.Failed, "", null) { } ///Initializes a new instance of the ///class /// public ManagementException(string message):this(ManagementStatus.Failed, message, null) { } ///Initializes a new instance of the /// The message that describes the error. ////// class with a specified error message. /// public ManagementException(string message,Exception innerException):this(innerException, message, null) { // if the exception passed is not a ManagementException, then initialize the ErrorCode to Failed if (!(innerException is ManagementException)) errorCode = ManagementStatus.Failed; } ///Initializes a empty new instance of the /// The message that describes the error. /// The exception that is the cause of the current exception. If the innerException /// parameter is not a null reference (Nothing in Visual Basic), the current exception is raised in a catch /// block that handles the inner exception. ///class /// /// ThePopulates the ///object with the data needed to /// serialize the /// object. to populate with data. /// The destination (see ) for this serialization. //FXCop requests explicit demand of the SerializationFormatter permission [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("errorCode", errorCode); info.AddValue("errorObject", errorObject); } private static string GetMessage(Exception e) { string msg = null; if (e is COMException) { // Try and get WMI error message. If not use the one in // the exception msg = GetMessage ((ManagementStatus)((COMException)e).ErrorCode); } if (null == msg) msg = e.Message; return msg; } private static string GetMessage(ManagementStatus errorCode) { string msg = null; IWbemStatusCodeText statusCode = null; int hr; statusCode = (IWbemStatusCodeText) new WbemStatusCodeText(); if (statusCode != null) { try { hr = statusCode.GetErrorCodeText_((int)errorCode, 0, 1, out msg); // Just in case it didn't like the flag=1, try it again // with flag=0. if (hr != 0) hr = statusCode.GetErrorCodeText_((int)errorCode, 0, 0, out msg); } catch {} } return msg; } /// /// ///Gets the extended error object provided by WMI. ////// public ManagementBaseObject ErrorInformation { get { return errorObject; } } ///A ///representing the /// extended error object provided by WMI, if available; /// otherwise. /// ///Gets the error code reported by WMI, which caused this exception. ////// A public ManagementStatus ErrorCode { get { return errorCode; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Serialization; using WbemClient_v1; using System.Security.Permissions; namespace System.Management { ///value representing the error code returned by /// the WMI operation. /// /// public enum ManagementStatus { ///Represents the enumeration of all WMI error codes that are currently defined. ////// The operation was successful. /// NoError = 0, ////// False = 1, ///This value is returned when no more objects /// are available, the number of objects returned is less than the number requested, /// or at the end of an enumeration. It is also returned when the method is called /// with a value of 0 for the ///parameter. /// ResetToDefault = 0x40002, ///An overridden property was deleted. This value is /// returned to signal that the original, non-overridden value has been restored as a /// result of the deletion. ////// Different = 0x40003, ///The compared items (such as objects and classes) /// are not identical. ////// Timedout = 0x40004, ///A call timed out. This is not an /// error condition; therefore, some results may have been returned. ////// NoMoreData = 0x40005, ///No more data is available from the enumeration; the /// user should terminate the enumeration. ////// OperationCanceled = 0x40006, ///The operation was /// canceled. ////// Pending = 0x40007, ///A request is still in progress; however, the results are not /// yet available. ////// DuplicateObjects = 0x40008, ///More than one copy of the same object was detected in /// the result set of an enumeration. ////// PartialResults = 0x40010, ///The user did not receive all of the requested objects /// because of inaccessible resources (other than security violations). ////// Failed = unchecked((int)0x80041001), ///The call failed. ////// NotFound = unchecked((int)0x80041002), ///The object could not be found. ////// The current user does not have permission to perform the /// action. /// AccessDenied = unchecked((int)0x80041003), ////// ProviderFailure = unchecked((int)0x80041004), ///The provider failed after /// initialization. ////// A type mismatch occurred. /// TypeMismatch = unchecked((int)0x80041005), ////// There was not enough memory for the operation. /// OutOfMemory = unchecked((int)0x80041006), ////// InvalidContext = unchecked((int)0x80041007), ///The context object is not valid. ////// InvalidParameter = unchecked((int)0x80041008), ///One of the parameters to the call is not correct. /// ////// NotAvailable = unchecked((int)0x80041009), ///The resource, typically a remote server, is not /// currently available. ////// CriticalError = unchecked((int)0x8004100A), ///An internal, critical, and unexpected error occurred. /// Report this error to Microsoft Product Support Services. ////// InvalidStream = unchecked((int)0x8004100B), ///One or more network packets were corrupted during a remote session. ////// NotSupported = unchecked((int)0x8004100C), ///The feature or operation is not supported. ////// The specified base class is not valid. /// InvalidSuperclass = unchecked((int)0x8004100D), ////// InvalidNamespace = unchecked((int)0x8004100E), ///The specified namespace could not be found. ////// The specified instance is not valid. /// InvalidObject = unchecked((int)0x8004100F), ////// The specified class is not valid. /// InvalidClass = unchecked((int)0x80041010), ////// A provider referenced in the schema does not have a /// corresponding registration. /// ProviderNotFound = unchecked((int)0x80041011), ////// A provider referenced in the schema has an incorrect or /// incomplete registration. /// InvalidProviderRegistration = unchecked((int)0x80041012), ////// COM cannot locate a provider referenced in the schema. /// ProviderLoadFailure = unchecked((int)0x80041013), ////// A component, such as a provider, failed to initialize for internal reasons. /// InitializationFailure = unchecked((int)0x80041014), ////// A networking error that prevents normal operation has /// occurred. /// TransportFailure = unchecked((int)0x80041015), ////// InvalidOperation = unchecked((int)0x80041016), ///The requested operation is not valid. This error usually /// applies to invalid attempts to delete classes or properties. ////// The query was not syntactically valid. /// InvalidQuery = unchecked((int)0x80041017), ////// InvalidQueryType = unchecked((int)0x80041018), ///The requested query language is not supported. ////// AlreadyExists = unchecked((int)0x80041019), ///In a put operation, the ////// flag was specified, but the instance already exists. /// OverrideNotAllowed = unchecked((int)0x8004101A), ///The add operation cannot be performed on the qualifier /// because the owning object does not permit overrides. ////// PropagatedQualifier = unchecked((int)0x8004101B), ///The user attempted to delete a qualifier that was not /// owned. The qualifier was inherited from a parent class. ////// PropagatedProperty = unchecked((int)0x8004101C), ///The user attempted to delete a property that was not /// owned. The property was inherited from a parent class. ////// The client made an unexpected and illegal sequence of /// calls. /// Unexpected = unchecked((int)0x8004101D), ////// IllegalOperation = unchecked((int)0x8004101E), ///The user requested an illegal operation, such as /// spawning a class from an instance. ////// CannotBeKey = unchecked((int)0x8004101F), ///There was an illegal attempt to specify a key qualifier /// on a property that cannot be a key. The keys are specified in the class /// definition for an object and cannot be altered on a per-instance basis. ////// IncompleteClass = unchecked((int)0x80041020), ///The current object is not a valid class definition. /// Either it is incomplete, or it has not been registered with WMI using /// ///(). /// Reserved for future use. /// InvalidSyntax = unchecked((int)0x80041021), ////// Reserved for future use. /// NondecoratedObject = unchecked((int)0x80041022), ////// ReadOnly = unchecked((int)0x80041023), ///The property that you are attempting to modify is read-only. ////// ProviderNotCapable = unchecked((int)0x80041024), ///The provider cannot perform the requested operation, such /// as requesting a query that is too complex, retrieving an instance, creating or /// updating a class, deleting a class, or enumerating a class. ////// ClassHasChildren = unchecked((int)0x80041025), ///An attempt was made to make a change that would /// invalidate a derived class. ////// ClassHasInstances = unchecked((int)0x80041026), ///An attempt has been made to delete or modify a class that /// has instances. ////// Reserved for future use. /// QueryNotImplemented = unchecked((int)0x80041027), ////// IllegalNull = unchecked((int)0x80041028), ///A value of null was specified for a property that may /// not be null, such as one that is marked by a ///, , or /// qualifier. /// InvalidQualifierType = unchecked((int)0x80041029), ///The value provided for a qualifier was not a /// legal qualifier type. ////// The CIM type specified for a property is not valid. /// InvalidPropertyType = unchecked((int)0x8004102A), ////// ValueOutOfRange = unchecked((int)0x8004102B), ///The request was made with an out-of-range value, or is /// incompatible with the type. ////// CannotBeSingleton = unchecked((int)0x8004102C), ///An illegal attempt was made to make a class singleton, /// such as when the class is derived from a non-singleton class. ////// The CIM type specified is not valid. /// InvalidCimType = unchecked((int)0x8004102D), ////// The requested method is not available. /// InvalidMethod = unchecked((int)0x8004102E), ////// InvalidMethodParameters = unchecked((int)0x8004102F), ///The parameters provided for the method are not valid. /// ////// There was an attempt to get qualifiers on a system /// property. /// SystemProperty = unchecked((int)0x80041030), ////// The property type is not recognized. /// InvalidProperty = unchecked((int)0x80041031), ////// CallCanceled = unchecked((int)0x80041032), ///An asynchronous process has been canceled internally or /// by the user. Note that because of the timing and nature of the asynchronous /// operation, the operation may not have been truly canceled. ////// ShuttingDown = unchecked((int)0x80041033), ///The user has requested an operation while WMI is in the /// process of quitting. ////// PropagatedMethod = unchecked((int)0x80041034), ///An attempt was made to reuse an existing method name from /// a base class, and the signatures did not match. ////// UnsupportedParameter = unchecked((int)0x80041035), ///One or more parameter values, such as a query text, is /// too complex or unsupported. WMI is requested to retry the operation /// with simpler parameters. ////// A parameter was missing from the method call. /// MissingParameterID = unchecked((int)0x80041036), ////// A method parameter has an invalid InvalidParameterID = unchecked((int)0x80041037), ///qualifier. /// /// NonconsecutiveParameterIDs = unchecked((int)0x80041038), ///One or more of the method parameters have ////// qualifiers that are out of sequence. /// ParameterIDOnRetval = unchecked((int)0x80041039), ///The return value for a method has an ///qualifier. /// /// The specified object path was invalid. /// InvalidObjectPath = unchecked((int)0x8004103A), ////// OutOfDiskSpace = unchecked((int)0x8004103B), ///There is not enough free disk space to continue the /// operation. ////// BufferTooSmall = unchecked((int)0x8004103C), ///The supplied buffer was too small to hold all the objects /// in the enumerator or to read a string property. ////// The provider does not support the requested put /// operation. /// UnsupportedPutExtension = unchecked((int)0x8004103D), ////// UnknownObjectType = unchecked((int)0x8004103E), ///An object with an incorrect type or version was /// encountered during marshaling. ////// UnknownPacketType = unchecked((int)0x8004103F), ///A packet with an incorrect type or version was /// encountered during marshaling. ////// The packet has an unsupported version. /// MarshalVersionMismatch = unchecked((int)0x80041040), ////// MarshalInvalidSignature = unchecked((int)0x80041041), ///The packet is corrupted. ////// An attempt has been made to mismatch qualifiers, such as /// putting [key] on an object instead of a property. /// InvalidQualifier = unchecked((int)0x80041042), ////// A duplicate parameter has been declared in a CIM method. /// InvalidDuplicateParameter = unchecked((int)0x80041043), ////// TooMuchData = unchecked((int)0x80041044), ///Reserved for future use. ////// ServerTooBusy = unchecked((int)0x80041045), ///The delivery of an event has failed. The provider may /// choose to re-raise the event. ////// The specified flavor was invalid. /// InvalidFlavor = unchecked((int)0x80041046), ////// CircularReference = unchecked((int)0x80041047), ///An attempt has been made to create a reference that is /// circular (for example, deriving a class from itself). ////// The specified class is not supported. /// UnsupportedClassUpdate = unchecked((int)0x80041048), ////// CannotChangeKeyInheritance = unchecked((int)0x80041049), ///An attempt was made to change a key when instances or derived /// classes are already using the key. ////// CannotChangeIndexInheritance = unchecked((int)0x80041050), ///An attempt was made to change an index when instances or derived /// classes are already using the index. ////// TooManyProperties = unchecked((int)0x80041051), ///An attempt was made to create more properties than the /// current version of the class supports. ////// UpdateTypeMismatch = unchecked((int)0x80041052), ///A property was redefined with a conflicting type in a /// derived class. ////// UpdateOverrideNotAllowed = unchecked((int)0x80041053), ///An attempt was made in a derived class to override a /// non-overrideable qualifier. ////// UpdatePropagatedMethod = unchecked((int)0x80041054), ///A method was redeclared with a conflicting signature in a /// derived class. ////// An attempt was made to execute a method not marked with /// [implemented] in any relevant class. /// MethodNotImplemented = unchecked((int)0x80041055), ////// MethodDisabled = unchecked((int)0x80041056), ///An attempt was made to execute a method marked with /// [disabled]. ////// RefresherBusy = unchecked((int)0x80041057), ///The refresher is busy with another operation. ////// UnparsableQuery = unchecked((int)0x80041058), ///The filtering query is syntactically invalid. ////// The FROM clause of a filtering query references a class /// that is not an event class. /// NotEventClass = unchecked((int)0x80041059), ////// A GROUP BY clause was used without the corresponding /// GROUP WITHIN clause. /// MissingGroupWithin = unchecked((int)0x8004105A), ////// A GROUP BY clause was used. Aggregation on all properties /// is not supported. /// MissingAggregationList = unchecked((int)0x8004105B), ////// PropertyNotAnObject = unchecked((int)0x8004105C), ///Dot notation was used on a property that is not an /// embedded object. ////// A GROUP BY clause references a property that is an /// embedded object without using dot notation. /// AggregatingByObject = unchecked((int)0x8004105D), ////// An event provider registration query /// ( UninterpretableProviderQuery = unchecked((int)0x8004105F), ///) did not specify the classes for which /// events were provided. /// /// BackupRestoreWinmgmtRunning = unchecked((int)0x80041060), ///An request was made to back up or restore the repository /// while WinMgmt.exe was using it. ////// QueueOverflow = unchecked((int)0x80041061), ///The asynchronous delivery queue overflowed from the /// event consumer being too slow. ////// The operation failed because the client did not have the /// necessary security privilege. /// PrivilegeNotHeld = unchecked((int)0x80041062), ////// InvalidOperator = unchecked((int)0x80041063), ///The operator is not valid for this property type. ////// LocalCredentials = unchecked((int)0x80041064), ///The user specified a username, password, or authority on a /// local connection. The user must use an empty user name and password and rely on /// default security. ////// CannotBeAbstract = unchecked((int)0x80041065), ///The class was made abstract when its base class is not /// abstract. ////// AmendedObject = unchecked((int)0x80041066), ///An amended object was used in a put operation without the /// WBEM_FLAG_USE_AMENDED_QUALIFIERS flag being specified. ////// The client was not retrieving objects quickly enough from /// an enumeration. /// ClientTooSlow = unchecked((int)0x80041067), ////// RegistrationTooBroad = unchecked((int)0x80042001), ///The provider registration overlaps with the system event /// domain. ////// RegistrationTooPrecise = unchecked((int)0x80042002) } ///A WITHIN clause was not used in this query. ////// ///Represents management exceptions. ////// [Serializable] public class ManagementException : SystemException { private ManagementBaseObject errorObject = null; private ManagementStatus errorCode = 0; internal static void ThrowWithExtendedInfo(ManagementStatus errorCode) { ManagementBaseObject errObj = null; string msg = null; //Try to get extended error info first, and save in errorObject member IWbemClassObjectFreeThreaded obj = WbemErrorInfo.GetErrorInfo(); if (obj != null) errObj = new ManagementBaseObject(obj); //If the error code is not a WMI one and there's an extended error object available, stick the message //from the extended error object in. if (((msg = GetMessage(errorCode)) == null) && (errObj != null)) try { msg = (string)errObj["Description"]; } catch {} throw new ManagementException(errorCode, msg, errObj); } internal static void ThrowWithExtendedInfo(Exception e) { ManagementBaseObject errObj = null; string msg = null; //Try to get extended error info first, and save in errorObject member IWbemClassObjectFreeThreaded obj = WbemErrorInfo.GetErrorInfo(); if (obj != null) errObj = new ManagementBaseObject(obj); //If the error code is not a WMI one and there's an extended error object available, stick the message //from the extended error object in. if (((msg = GetMessage(e)) == null) && (errObj != null)) try { msg = (string)errObj["Description"]; } catch {} throw new ManagementException(e, msg, errObj); } internal ManagementException(ManagementStatus errorCode, string msg, ManagementBaseObject errObj) : base (msg) { this.errorCode = errorCode; this.errorObject = errObj; } internal ManagementException(Exception e, string msg, ManagementBaseObject errObj) : base (msg, e) { try { if (e is ManagementException) { errorCode = ((ManagementException)e).ErrorCode; // May/may not have extended error info. // if (errorObject != null) errorObject = (ManagementBaseObject)((ManagementException)e).errorObject.Clone(); else errorObject = null; } else if (e is COMException) errorCode = (ManagementStatus)((COMException)e).ErrorCode; else errorCode = (ManagementStatus)this.HResult; } catch {} } ///using System; /// using System.Management; /// /// // This sample demonstrates how to display error /// // information stored in a ManagementException object. /// class Sample_ManagementException /// { /// public static int Main(string[] args) /// { /// try /// { /// ManagementObject disk = /// new ManagementObject("Win32_LogicalDisk.DeviceID='BAD:'"); /// disk.Get(); // throws ManagementException /// Console.WriteLine("This shouldn't be displayed."); /// } /// catch (ManagementException e) /// { /// Console.WriteLine("ErrorCode " + e.ErrorCode); /// Console.WriteLine("Message " + e.Message); /// Console.WriteLine("Source " + e.Source); /// if (e.ErrorInformation) //extended error object /// Console.WriteLine("Extended Description : " + e.ErrorInformation["Description"]); /// } /// return 0; /// } /// } ///
///Imports System /// Imports System.Management /// /// ' This sample demonstrates how to display error /// ' information stored in a ManagementException object. /// Class Sample_ManagementException /// Overloads Public Shared Function Main(args() As String) As Integer /// Try /// Dim disk As New ManagementObject("Win32_LogicalDisk.DeviceID='BAD:'") /// disk.Get() ' throws ManagementException /// Console.WriteLine("This shouldn't be displayed.") /// Catch e As ManagementException /// Console.WriteLine("ErrorCode " & e.ErrorCode) /// Console.WriteLine("Message " & e.Message) /// Console.WriteLine("Source " & e.Source) /// If e.ErrorInformation != Nothing Then 'extended error object /// Console.WriteLine("Extended Description : " & e.ErrorInformation("Description")) /// End If /// End Try /// Return 0 /// End Function /// End Class ///
////// /// TheInitializes a new instance of the ///class that is serializable. to populate with data. /// The destination (see ) for this serialization. protected ManagementException(SerializationInfo info, StreamingContext context) : base(info, context) { errorCode = (ManagementStatus)info.GetValue("errorCode", typeof(ManagementStatus)); errorObject = info.GetValue("errorObject", typeof(ManagementBaseObject)) as ManagementBaseObject; } /// /// public ManagementException():this(ManagementStatus.Failed, "", null) { } ///Initializes a new instance of the ///class /// public ManagementException(string message):this(ManagementStatus.Failed, message, null) { } ///Initializes a new instance of the /// The message that describes the error. ////// class with a specified error message. /// public ManagementException(string message,Exception innerException):this(innerException, message, null) { // if the exception passed is not a ManagementException, then initialize the ErrorCode to Failed if (!(innerException is ManagementException)) errorCode = ManagementStatus.Failed; } ///Initializes a empty new instance of the /// The message that describes the error. /// The exception that is the cause of the current exception. If the innerException /// parameter is not a null reference (Nothing in Visual Basic), the current exception is raised in a catch /// block that handles the inner exception. ///class /// /// ThePopulates the ///object with the data needed to /// serialize the /// object. to populate with data. /// The destination (see ) for this serialization. //FXCop requests explicit demand of the SerializationFormatter permission [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("errorCode", errorCode); info.AddValue("errorObject", errorObject); } private static string GetMessage(Exception e) { string msg = null; if (e is COMException) { // Try and get WMI error message. If not use the one in // the exception msg = GetMessage ((ManagementStatus)((COMException)e).ErrorCode); } if (null == msg) msg = e.Message; return msg; } private static string GetMessage(ManagementStatus errorCode) { string msg = null; IWbemStatusCodeText statusCode = null; int hr; statusCode = (IWbemStatusCodeText) new WbemStatusCodeText(); if (statusCode != null) { try { hr = statusCode.GetErrorCodeText_((int)errorCode, 0, 1, out msg); // Just in case it didn't like the flag=1, try it again // with flag=0. if (hr != 0) hr = statusCode.GetErrorCodeText_((int)errorCode, 0, 0, out msg); } catch {} } return msg; } /// /// ///Gets the extended error object provided by WMI. ////// public ManagementBaseObject ErrorInformation { get { return errorObject; } } ///A ///representing the /// extended error object provided by WMI, if available; /// otherwise. /// ///Gets the error code reported by WMI, which caused this exception. ////// A public ManagementStatus ErrorCode { get { return errorCode; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.value representing the error code returned by /// the WMI operation. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- IndependentAnimationStorage.cs
- QuaternionAnimation.cs
- TickBar.cs
- SafeArchiveContext.cs
- RegionData.cs
- ObjectContextServiceProvider.cs
- SqlDataAdapter.cs
- XomlDesignerLoader.cs
- PowerEase.cs
- FontCacheUtil.cs
- ModifyActivitiesPropertyDescriptor.cs
- TextSearch.cs
- StrongTypingException.cs
- ObjectDataSourceView.cs
- ListCollectionView.cs
- ConfigurationStrings.cs
- DataControlFieldCollection.cs
- XmlSchemaAnyAttribute.cs
- ParseHttpDate.cs
- DataGridViewRowConverter.cs
- GridViewRow.cs
- ArraySet.cs
- TagPrefixInfo.cs
- SafeCryptHandles.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- Signature.cs
- DirectoryNotFoundException.cs
- AudioBase.cs
- ZipIOLocalFileBlock.cs
- HiddenFieldPageStatePersister.cs
- Int32Converter.cs
- WebPartUserCapability.cs
- HttpRuntimeSection.cs
- WindowsHyperlink.cs
- TreeViewAutomationPeer.cs
- CompensatableTransactionScopeActivityDesigner.cs
- X509CertificateInitiatorClientCredential.cs
- EpmHelper.cs
- AutomationIdentifierGuids.cs
- SingleQueryOperator.cs
- SynchronizingStream.cs
- PriorityRange.cs
- cookie.cs
- WebConfigurationManager.cs
- AdornerLayer.cs
- SqlCrossApplyToCrossJoin.cs
- StateBag.cs
- Matrix.cs
- XmlNamedNodeMap.cs
- DataGridTextBoxColumn.cs
- UTF32Encoding.cs
- DrawingVisualDrawingContext.cs
- WorkflowWebHostingModule.cs
- ConfigXmlReader.cs
- BamlCollectionHolder.cs
- GCHandleCookieTable.cs
- TextLineResult.cs
- SQLRoleProvider.cs
- SchemaImporterExtensionElement.cs
- ReachDocumentPageSerializerAsync.cs
- MetadataPropertyvalue.cs
- DuplexChannelFactory.cs
- UnsafeCollabNativeMethods.cs
- safesecurityhelperavalon.cs
- PeerNameRecord.cs
- RegexReplacement.cs
- AppSecurityManager.cs
- CaseKeyBox.ViewModel.cs
- SpeechSynthesizer.cs
- LinqDataSourceDisposeEventArgs.cs
- ValueQuery.cs
- ParserContext.cs
- CodeTypeReferenceExpression.cs
- AnimatedTypeHelpers.cs
- ActivityTypeCodeDomSerializer.cs
- EasingKeyFrames.cs
- COM2IDispatchConverter.cs
- SocketInformation.cs
- Message.cs
- XmlStreamStore.cs
- TypedElement.cs
- ReferenceEqualityComparer.cs
- CodeIterationStatement.cs
- FrameworkTextComposition.cs
- DataChangedEventManager.cs
- NullableDecimalAverageAggregationOperator.cs
- AccessedThroughPropertyAttribute.cs
- SelectionGlyphBase.cs
- MimeObjectFactory.cs
- XmlTextWriter.cs
- XmlImplementation.cs
- ViewGenerator.cs
- CounterSampleCalculator.cs
- RemotingException.cs
- HttpModulesSection.cs
- EllipseGeometry.cs
- ChannelSinkStacks.cs
- WebPartConnectionsCancelVerb.cs
- ToolStripDropDown.cs
- SafeNativeMethods.cs