コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: WbemErrorInfo.cs プロジェクト: modulexcite/pash-1
        public static IWbemClassObjectFreeThreaded GetErrorInfo()
        {
            IntPtr     intPtr;
            IErrorInfo errorInfo = WbemErrorInfo.GetErrorInfo(0);

            if (errorInfo != null)
            {
                IntPtr unknownForObject = Marshal.GetIUnknownForObject(errorInfo);
                Marshal.QueryInterface(unknownForObject, ref IWbemClassObjectFreeThreaded.IID_IWbemClassObject, out intPtr);
                Marshal.Release(unknownForObject);
                if (intPtr != IntPtr.Zero)
                {
                    return(new IWbemClassObjectFreeThreaded(intPtr));
                }
            }
            return(null);
        }
コード例 #3
0
        internal static void ThrowWithExtendedInfo(ManagementStatus errorCode)
        {
            ManagementBaseObject errObj = null;
            string msg = null;
            IWbemClassObjectFreeThreaded errorInfo = WbemErrorInfo.GetErrorInfo();

            if (errorInfo != null)
            {
                errObj = new ManagementBaseObject(errorInfo);
            }
            if (((msg = GetMessage(errorCode)) == null) && (errObj != null))
            {
                try
                {
                    msg = (string)errObj["Description"];
                }
                catch
                {
                }
            }
            throw new ManagementException(errorCode, msg, errObj);
        }
コード例 #4
0
        internal static void ThrowIfFailed(int hresult, bool supportsErrorInfo)
        {
/*
 *          if (hresult < 0)
 *          {
 *              if ((hresult & 0xfffff000) == 0x80041000)
 *                  ManagementException.ThrowWithExtendedInfo((ManagementStatus)hresult);
 *              else
 *                  Marshal.ThrowExceptionForHR(hresult);
 *          }
 */
            ManagementBaseObject errObj = null;
            string msg = null;

            if (supportsErrorInfo)
            {
                //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((ManagementStatus)hresult)) == null) && (errObj != null))
            {
                try
                {
                    msg = (string)errObj["Description"];
                }
                catch {}
            }

            throw new ManagementException((ManagementStatus)hresult, msg, errObj);
        }
コード例 #5
0
        internal static void ThrowWithExtendedInfo(Exception e)
        {
            ManagementBaseObject         managementBaseObject = null;
            IWbemClassObjectFreeThreaded errorInfo            = WbemErrorInfo.GetErrorInfo();

            if (errorInfo != null)
            {
                managementBaseObject = new ManagementBaseObject(errorInfo);
            }
            string message = ManagementException.GetMessage(e);
            string item    = message;

            if (message == null && managementBaseObject != null)
            {
                try
                {
                    item = (string)managementBaseObject["Description"];
                }
                catch
                {
                }
            }
            throw new ManagementException(e, item, managementBaseObject);
        }