Ejemplo n.º 1
0
        /// <summary>
        /// <para>Removes a <see cref='System.Management.MethodData'/> from the <see cref='System.Management.MethodDataCollection'/>.</para>
        /// </summary>
        /// <param name='methodName'>The name of the method to remove from the collection.</param>
        /// <remarks>
        ///    <para>
        ///       Removing <see cref='System.Management.MethodData'/> objects from the <see cref='System.Management.MethodDataCollection'/>
        ///       can only be done when the class has no
        ///       instances. Any other case will result in an exception.</para>
        /// </remarks>
        public virtual void Remove(string methodName)
        {
            if (parent.GetType() == typeof(ManagementObject)) //can't remove methods from instance
            {
                throw new InvalidOperationException();
            }

            int status = (int)ManagementStatus.Failed;

            try
            {
                status = parent.wbemObject.DeleteMethod_(methodName);
            }
            catch (COMException e)
            {
                ManagementException.ThrowWithExtendedInfo(e);
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f());
            }
        }