예제 #1
0
        internal static string GetNamespacePath(IWbemPath wbemPath, int flags)
        {
            string empty = string.Empty;

            if (wbemPath != null)
            {
                uint num             = 0;
                int  namespaceCount_ = wbemPath.GetNamespaceCount_(out num);
                if (namespaceCount_ >= 0 && num > 0)
                {
                    int num1 = 0;
                    namespaceCount_ = wbemPath.GetText_(flags, out num1, null);
                    if (namespaceCount_ >= 0 && num1 > 0)
                    {
                        empty           = new string('0', num1 - 1);
                        namespaceCount_ = wbemPath.GetText_(flags, out num1, empty);
                    }
                }
                if (namespaceCount_ < 0 && namespaceCount_ != -2147217400)
                {
                    if (((long)namespaceCount_ & (long)-4096) != (long)-2147217408)
                    {
                        Marshal.ThrowExceptionForHR(namespaceCount_);
                    }
                    else
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)namespaceCount_);
                    }
                }
            }
            return(empty);
        }
        internal static string GetNamespacePath(IWbemPath wbemPath, int flags)
        {
            string pszText = string.Empty;

            if (wbemPath != null)
            {
                uint puCount   = 0;
                int  errorCode = 0;
                errorCode = wbemPath.GetNamespaceCount_(out puCount);
                if ((errorCode >= 0) && (puCount > 0))
                {
                    uint puBuffLength = 0;
                    errorCode = wbemPath.GetText_(flags, ref puBuffLength, null);
                    if ((errorCode >= 0) && (puBuffLength > 0))
                    {
                        pszText   = new string('0', ((int)puBuffLength) - 1);
                        errorCode = wbemPath.GetText_(flags, ref puBuffLength, pszText);
                    }
                }
                if ((errorCode >= 0) || (errorCode == -2147217400))
                {
                    return(pszText);
                }
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                    return(pszText);
                }
                Marshal.ThrowExceptionForHR(errorCode);
            }
            return(pszText);
        }
예제 #3
0
        private static string GetWbemPath(IWbemPath wbemPath)
        {
            string pathStr = string.Empty;

            if (null != wbemPath)
            {
                // Requesting the path from a parser which has
                // been only given a relative path results in an incorrect
                // value being returned (e.g. \\.\win32_logicaldisk). To work
                // around this we check if there are any namespaces,
                // and if not ask for the relative path instead.
                int  flags  = (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_TOO;
                uint nCount = 0;

                int status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0)
                {
                    if (0 == nCount)
                    {
                        flags = (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_RELATIVE_ONLY;
                    }

                    // Get the space we need to reserve
                    uint bufLen = 0;

                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && 0 < bufLen)
                    {
                        char[] pathChars = new char[(int)bufLen];
                        status  = wbemPath.GetText_(flags, ref bufLen, pathChars);
                        pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER)
                    {
                        // Interpret as unspecified - return ""
                    }

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

            return(pathStr);
        }
예제 #4
0
        private static string GetWbemPath(IWbemPath wbemPath)
        {
            String pathStr = String.Empty;

            if (null != wbemPath)
            {
                //



                int  flags  = (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_TOO;
                uint nCount = 0;

                int status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0)
                {
                    if (0 == nCount)
                    {
                        flags = (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_RELATIVE_ONLY;
                    }

                    // Get the space we need to reserve
                    uint bufLen = 0;

                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && 0 < bufLen)
                    {
                        pathStr = new String('0', (int)bufLen - 1);
                        status  = wbemPath.GetText_(flags, ref bufLen, pathStr);
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER)
                    {
                        // Interpret as unspecified - return ""
                    }

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

            return(pathStr);
        }
예제 #5
0
        internal static string GetNamespacePath(IWbemPath wbemPath, int flags)
        {
            string pathStr = string.Empty;

            if (null != wbemPath)
            {
                // Requesting the namespace path from a parser which has
                // been only given a relative path results in an incorrect
                // value being returned (e.g. \\.\). To work
                // around this, check if there are any namespaces,
                // and if not just return "".
                uint nCount = 0;
                int  status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0 && nCount > 0)
                {
                    // Get the space we need to reserve
                    uint bufLen = 0;
                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && bufLen > 0)
                    {
                        char[] pathChars = new char[(int)bufLen];
                        status  = wbemPath.GetText_(flags, ref bufLen, pathChars);
                        pathStr = new string(pathChars, 0, Array.IndexOf(pathChars, '\0'));
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER)
                    {
                        // Interpret as unspecified - return ""
                    }
                    else if ((status & 0xfffff000) == 0x80041000)
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f());
                    }
                }
            }

            return(pathStr);
        }
예제 #6
0
        internal string GetNamespacePath(IWbemPath wbemPath, int flags)
        {
            string pathStr = String.Empty;

            if (null != wbemPath)
            {
                // TODO - due to a bug in the current WMI path
                // parser, requesting the namespace path from a parser which has
                // been only given a relative path results in an incorrect
                // value being returned (e.g. \\.\). To work
                // around this for now we check if there are any namespaces,
                // and if not just return "".
                uint nCount = 0;
                int  status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0 && nCount > 0)
                {
                    // Get the space we need to reserve
                    uint bufLen = 0;
                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && bufLen > 0)
                    {
                        pathStr = new String('0', (int)bufLen - 1);
                        status  = wbemPath.GetText_(flags, ref bufLen, pathStr);
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER)
                    {
                        ;                               // Interpret as unspecified - return ""
                    }
                    else if ((status & 0xfffff000) == 0x80041000)
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(status);
                    }
                }
            }

            return(pathStr);
        }
예제 #7
0
        internal static string GetNamespacePath(IWbemPath wbemPath, int flags)
        {
            string pathStr = String.Empty;

            if (null != wbemPath)
            {
                //



                uint nCount = 0;
                int  status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0 && nCount > 0)
                {
                    // Get the space we need to reserve
                    uint bufLen = 0;
                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && bufLen > 0)
                    {
                        pathStr = new String('0', (int)bufLen - 1);
                        status  = wbemPath.GetText_(flags, ref bufLen, pathStr);
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER)
                    {
                        // Interpret as unspecified - return ""
                    }
                    else if ((status & 0xfffff000) == 0x80041000)
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(status);
                    }
                }
            }

            return(pathStr);
        }
예제 #8
0
        private static string GetWbemPath(IWbemPath wbemPath)
        {
            string empty = string.Empty;

            if (wbemPath != null)
            {
                int  num             = 4;
                uint num1            = 0;
                int  namespaceCount_ = wbemPath.GetNamespaceCount_(out num1);
                if (namespaceCount_ >= 0)
                {
                    if (num1 == 0)
                    {
                        num = 2;
                    }
                    int num2 = 0;
                    namespaceCount_ = wbemPath.GetText_(num, out num2, null);
                    if (namespaceCount_ >= 0 && 0 < num2)
                    {
                        empty           = new string('0', num2 - 1);
                        namespaceCount_ = wbemPath.GetText_(num, out num2, empty);
                    }
                }
                if (namespaceCount_ < 0 && namespaceCount_ != -2147217400)
                {
                    if (((long)namespaceCount_ & (long)-4096) != (long)-2147217408)
                    {
                        Marshal.ThrowExceptionForHR(namespaceCount_);
                    }
                    else
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)namespaceCount_);
                    }
                }
            }
            return(empty);
        }
예제 #9
0
        internal string SetNamespacePath(string nsPath, out bool bChange)
        {
            int namespaceCount_ = 0;

            bChange = false;
            if (!ManagementPath.IsValidNamespaceSyntax(nsPath))
            {
                ManagementException.ThrowWithExtendedInfo(ManagementStatus.InvalidNamespace);
            }
            IWbemPath wbemPath = this.CreateWbemPath(nsPath);

            if (this.wmiPath != null)
            {
                if (this.isWbemPathShared)
                {
                    this.wmiPath          = this.CreateWbemPath(this.GetWbemPath());
                    this.isWbemPathShared = false;
                }
            }
            else
            {
                this.wmiPath = this.CreateWbemPath("");
            }
            string namespacePath = ManagementPath.GetNamespacePath(this.wmiPath, 16);
            string str           = ManagementPath.GetNamespacePath(wbemPath, 16);

            if (string.Compare(namespacePath, str, StringComparison.OrdinalIgnoreCase) != 0)
            {
                this.wmiPath.RemoveAllNamespaces_();
                bChange = true;
                uint num = 0;
                namespaceCount_ = wbemPath.GetNamespaceCount_(out num);
                if (namespaceCount_ >= 0)
                {
                    for (uint i = 0; i < num; i++)
                    {
                        int num1 = 0;
                        namespaceCount_ = wbemPath.GetNamespaceAt_(i, out num1, null);
                        if (namespaceCount_ < 0)
                        {
                            break;
                        }
                        string str1 = new string ('0', num1 - 1);
                        namespaceCount_ = wbemPath.GetNamespaceAt_(i, out num1, str1);
                        if (namespaceCount_ < 0)
                        {
                            break;
                        }
                        namespaceCount_ = this.wmiPath.SetNamespaceAt_(i, str1);
                        if (namespaceCount_ < 0)
                        {
                            break;
                        }
                    }
                }
            }
            if (namespaceCount_ >= 0 && nsPath.Length > 1 && (nsPath [0] == '\\' && nsPath [1] == '\\' || nsPath [0] == '/' && nsPath [1] == '/'))
            {
                int num2 = 0;
                namespaceCount_ = wbemPath.GetServer_(out num2, null);
                if (namespaceCount_ < 0 || num2 <= 0)
                {
                    if (namespaceCount_ == -2147217399)
                    {
                        namespaceCount_ = 0;
                    }
                }
                else
                {
                    string str2 = new string ('0', num2 - 1);
                    namespaceCount_ = wbemPath.GetServer_(out num2, str2);
                    if (namespaceCount_ >= 0)
                    {
                        num2            = 0;
                        namespaceCount_ = this.wmiPath.GetServer_(out num2, null);
                        if (namespaceCount_ < 0)
                        {
                            if (namespaceCount_ == -2147217399)
                            {
                                namespaceCount_ = this.wmiPath.SetServer_(str2);
                                if (namespaceCount_ >= 0)
                                {
                                    bChange = true;
                                }
                            }
                        }
                        else
                        {
                            string str3 = new string ('0', num2 - 1);
                            namespaceCount_ = this.wmiPath.GetServer_(out num2, str3);
                            if (namespaceCount_ >= 0 && string.Compare(str3, str2, StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                namespaceCount_ = this.wmiPath.SetServer_(str2);
                            }
                        }
                    }
                }
            }
            else if (namespaceCount_ <= 0 && nsPath.Length > 1)
            {
                this.wmiPath.SetNamespaceAt_(0, nsPath);
                uint nsCount = 0;
                namespaceCount_ = (int)nsCount;
                this.wmiPath.GetNamespaceCount_(out nsCount);
                str = nsPath;
            }

            if (namespaceCount_ < 0)
            {
                if (((long)namespaceCount_ & (long)-4096) != (long)-2147217408)
                {
                    Marshal.ThrowExceptionForHR(namespaceCount_);
                }
                else
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)namespaceCount_);
                }
            }
            return(str);
        }
예제 #10
0
        internal string SetNamespacePath(string nsPath, out bool bChange)
        {
            int       status     = (int)ManagementStatus.NoError;
            string    nsOrg      = null;
            string    nsNew      = null;
            IWbemPath wmiPathTmp = null;

            bChange = false;

            Debug.Assert(nsPath != null);

            //Do some validation on the path to make sure it is a valid namespace path (at least syntactically)
            if (!IsValidNamespaceSyntax(nsPath))
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)tag_WBEMSTATUS.WBEM_E_INVALID_NAMESPACE);
            }

            wmiPathTmp = CreateWbemPath(nsPath);
            if (wmiPath == null)
            {
                wmiPath = this.CreateWbemPath("");
            }
            else if (isWbemPathShared)
            {
                // Check if this IWbemPath is shared among multiple managed objects.
                // With this write, it will have to maintain its own copy.
                wmiPath          = CreateWbemPath(this.GetWbemPath());
                isWbemPathShared = false;
            }

            nsOrg = GetNamespacePath(wmiPath,
                                     (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_NAMESPACE_ONLY);
            nsNew = GetNamespacePath(wmiPathTmp,
                                     (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_NAMESPACE_ONLY);

            if (!string.Equals(nsOrg, nsNew, StringComparison.OrdinalIgnoreCase))
            {
                wmiPath.RemoveAllNamespaces_();                                 // Out with the old... Ignore status code.

                // Add the new ones in
                bChange = true;                                                 // Now dirty from above.
                uint nCount = 0;
                status = wmiPathTmp.GetNamespaceCount_(out nCount);

                if (status >= 0)
                {
                    for (uint i = 0; i < nCount; i++)
                    {
                        uint uLen = 0;
                        status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, null);

                        if (status >= 0)
                        {
                            char[] space = new char[(int)uLen];
                            status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, space);
                            if (status >= 0)
                            {
                                status = wmiPath.SetNamespaceAt_(i, space);

                                if (status < 0)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                ;
            }            // Continue on. Could have different server name, same ns specified.

            //
            // Update Server property if specified in the namespace.
            // eg: "\\MyServer\root\cimv2".
            //
            if (status >= 0 && nsPath.Length > 1 &&
                (nsPath[0] == '\\' && nsPath[1] == '\\' ||
                 nsPath[0] == '/' && nsPath[1] == '/'))
            {
                uint uLen = 0;
                status = wmiPathTmp.GetServer_(ref uLen, null);

                if (status >= 0 && uLen > 0)
                {
                    char[] newServerChars = new char[(int)uLen];
                    status = wmiPathTmp.GetServer_(ref uLen, newServerChars);
                    string serverNew = new string(newServerChars, 0, Array.IndexOf(newServerChars, '\0'));

                    if (status >= 0)
                    {
                        // Compare server name on this object, if specified, to the caller's.
                        //     Update this object if different or unspecified.
                        uLen   = 0;
                        status = wmiPath.GetServer_(ref uLen, null);            // NB: Cannot use property get since it may throw.

                        if (status >= 0)
                        {
                            char[] orgServerChars = new char[(int)uLen];
                            status = wmiPath.GetServer_(ref uLen, orgServerChars);
                            string serverOrg = new string(orgServerChars, 0, Array.IndexOf(orgServerChars, '\0'));

                            if (status >= 0 && !string.Equals(serverOrg, serverNew, StringComparison.OrdinalIgnoreCase))
                            {
                                status = wmiPath.SetServer_(serverNew);
                            }
                        }
                        else if (status == (int)tag_WBEMSTATUS.WBEM_E_NOT_AVAILABLE)
                        {
                            status = wmiPath.SetServer_(serverNew);
                            if (status >= 0)
                            {
                                bChange = true;
                            }
                        }
                    }
                }
                else if (status == (int)tag_WBEMSTATUS.WBEM_E_NOT_AVAILABLE)    // No caller-supplied server name;
                {
                    status = (int)ManagementStatus.NoError;                     // Ignore error.
                }
            }

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

            return(nsNew);
        }
        internal string SetNamespacePath(string nsPath, out bool bChange)
        {
            int       errorCode = 0;
            string    strA      = null;
            string    strB      = null;
            IWbemPath wbemPath  = null;

            bChange = false;
            if (!IsValidNamespaceSyntax(nsPath))
            {
                ManagementException.ThrowWithExtendedInfo(ManagementStatus.InvalidNamespace);
            }
            wbemPath = this.CreateWbemPath(nsPath);
            if (this.wmiPath == null)
            {
                this.wmiPath = this.CreateWbemPath("");
            }
            else if (this.isWbemPathShared)
            {
                this.wmiPath          = this.CreateWbemPath(this.GetWbemPath());
                this.isWbemPathShared = false;
            }
            strA = GetNamespacePath(this.wmiPath, 0x10);
            strB = GetNamespacePath(wbemPath, 0x10);
            if (string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase) != 0)
            {
                this.wmiPath.RemoveAllNamespaces_();
                bChange = true;
                uint puCount = 0;
                errorCode = wbemPath.GetNamespaceCount_(out puCount);
                if (errorCode >= 0)
                {
                    for (uint i = 0; i < puCount; i++)
                    {
                        uint puNameBufLength = 0;
                        errorCode = wbemPath.GetNamespaceAt_(i, ref puNameBufLength, null);
                        if (errorCode < 0)
                        {
                            break;
                        }
                        string pName = new string('0', ((int)puNameBufLength) - 1);
                        errorCode = wbemPath.GetNamespaceAt_(i, ref puNameBufLength, pName);
                        if (errorCode < 0)
                        {
                            break;
                        }
                        errorCode = this.wmiPath.SetNamespaceAt_(i, pName);
                        if (errorCode < 0)
                        {
                            break;
                        }
                    }
                }
            }
            if (((errorCode >= 0) && (nsPath.Length > 1)) && (((nsPath[0] == '\\') && (nsPath[1] == '\\')) || ((nsPath[0] == '/') && (nsPath[1] == '/'))))
            {
                uint num5 = 0;
                errorCode = wbemPath.GetServer_(ref num5, null);
                if ((errorCode >= 0) && (num5 > 0))
                {
                    string str4 = new string('0', ((int)num5) - 1);
                    errorCode = wbemPath.GetServer_(ref num5, str4);
                    if (errorCode >= 0)
                    {
                        num5      = 0;
                        errorCode = this.wmiPath.GetServer_(ref num5, null);
                        if (errorCode >= 0)
                        {
                            string str5 = new string('0', ((int)num5) - 1);
                            errorCode = this.wmiPath.GetServer_(ref num5, str5);
                            if ((errorCode >= 0) && (string.Compare(str5, str4, StringComparison.OrdinalIgnoreCase) != 0))
                            {
                                errorCode = this.wmiPath.SetServer_(str4);
                            }
                        }
                        else if (errorCode == -2147217399)
                        {
                            errorCode = this.wmiPath.SetServer_(str4);
                            if (errorCode >= 0)
                            {
                                bChange = true;
                            }
                        }
                    }
                }
                else if (errorCode == -2147217399)
                {
                    errorCode = 0;
                }
            }
            if (errorCode < 0)
            {
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                    return(strB);
                }
                Marshal.ThrowExceptionForHR(errorCode);
            }
            return(strB);
        }
 private static string GetWbemPath(IWbemPath wbemPath)
 {
     string pszText = string.Empty;
     if (wbemPath != null)
     {
         int lFlags = 4;
         uint puCount = 0;
         int errorCode = 0;
         errorCode = wbemPath.GetNamespaceCount_(out puCount);
         if (errorCode >= 0)
         {
             if (puCount == 0)
             {
                 lFlags = 2;
             }
             uint puBuffLength = 0;
             errorCode = wbemPath.GetText_(lFlags, ref puBuffLength, null);
             if ((errorCode >= 0) && (0 < puBuffLength))
             {
                 pszText = new string('0', ((int) puBuffLength) - 1);
                 errorCode = wbemPath.GetText_(lFlags, ref puBuffLength, pszText);
             }
         }
         if ((errorCode >= 0) || (errorCode == -2147217400))
         {
             return pszText;
         }
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             return pszText;
         }
         Marshal.ThrowExceptionForHR(errorCode);
     }
     return pszText;
 }
예제 #13
0
        internal static string GetNamespacePath(IWbemPath wbemPath, int flags)
        {
            string pathStr = String.Empty;

            if (null != wbemPath)
            {
                // 





                uint nCount = 0;
                int status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0 && nCount > 0)
                {
                    // Get the space we need to reserve
                    uint bufLen = 0;
                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && bufLen > 0)
                    {
                        pathStr = new String ('0', (int) bufLen-1);
                        status = wbemPath.GetText_(flags, ref bufLen, pathStr);
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER) 
                    {
                        // Interpret as unspecified - return ""
                    }
                    else if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }

            return pathStr;
        }
예제 #14
0
        private static string GetWbemPath(IWbemPath wbemPath)
        {
            String pathStr = String.Empty;

            if (null != wbemPath)
            {
                // 





                int flags = (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_TOO;
                uint nCount = 0;

                int status = (int)ManagementStatus.NoError;

                status = wbemPath.GetNamespaceCount_(out nCount);

                if (status >= 0)
                {
                    if (0 == nCount)
                        flags = (int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_RELATIVE_ONLY;

                    // Get the space we need to reserve
                    uint bufLen = 0;
                
                    status = wbemPath.GetText_(flags, ref bufLen, null);

                    if (status >= 0 && 0 < bufLen)
                    {
                        pathStr = new String ('0', (int) bufLen-1);
                        status = wbemPath.GetText_(flags, ref bufLen, pathStr);
                    }
                }

                if (status < 0)
                {
                    if (status == (int)tag_WBEMSTATUS.WBEM_E_INVALID_PARAMETER) 
                    {
                        // Interpret as unspecified - return ""
                    }
                    
                    else if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }

            return pathStr;
        }
예제 #15
0
		private static string GetWbemPath(IWbemPath wbemPath)
		{
			string empty = string.Empty;
			if (wbemPath != null)
			{
				int num = 4;
				uint num1 = 0;
				int namespaceCount_ = wbemPath.GetNamespaceCount_(out num1);
				if (namespaceCount_ >= 0)
				{
					if (num1 == 0)
					{
						num = 2;
					}
					int num2 = 0;
					namespaceCount_ = wbemPath.GetText_(num, out num2, null);
					if (namespaceCount_ >= 0 && 0 < num2)
					{
						empty = new string('0', num2 - 1);
						namespaceCount_ = wbemPath.GetText_(num, out num2, empty);
					}
				}
				if (namespaceCount_ < 0 && namespaceCount_ != -2147217400)
				{
					if (((long)namespaceCount_ & (long)-4096) != (long)-2147217408)
					{
						Marshal.ThrowExceptionForHR(namespaceCount_);
					}
					else
					{
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)namespaceCount_);
					}
				}
			}
			return empty;
		}
예제 #16
0
		internal static string GetNamespacePath(IWbemPath wbemPath, int flags)
		{
			string empty = string.Empty;
			if (wbemPath != null)
			{
				uint num = 0;
				int namespaceCount_ = wbemPath.GetNamespaceCount_(out num);
				if (namespaceCount_ >= 0 && num > 0)
				{
					int num1 = 0;
					namespaceCount_ = wbemPath.GetText_(flags, out num1, null);
					if (namespaceCount_ >= 0 && num1 > 0)
					{
						empty = new string('0', num1 - 1);
						namespaceCount_ = wbemPath.GetText_(flags, out num1, empty);
					}
				}
				if (namespaceCount_ < 0 && namespaceCount_ != -2147217400)
				{
					if (((long)namespaceCount_ & (long)-4096) != (long)-2147217408)
					{
						Marshal.ThrowExceptionForHR(namespaceCount_);
					}
					else
					{
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)namespaceCount_);
					}
				}
			}
			return empty;
		}