Example #1
0
        internal void UpdateRelativePath(string relPath)
        {
            string str;

            if (relPath != null)
            {
                string namespacePath = this.GetNamespacePath(8);
                if (namespacePath.Length <= 0)
                {
                    str = relPath;
                }
                else
                {
                    str = string.Concat(namespacePath, ":", relPath);
                }
                if (this.isWbemPathShared)
                {
                    this.wmiPath          = this.CreateWbemPath(this.GetWbemPath());
                    this.isWbemPathShared = false;
                }
                this.SetWbemPath(str);
                return;
            }
            else
            {
                return;
            }
        }
        private void SetWbemPath(IWbemPath wbemPath, string path)
        {
            if (null != wbemPath)
            {
                uint flags = (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_CREATE_ACCEPT_ALL;

                //For now we have to special-case the "root" namespace -
                //  this is because in the case of "root", the path parser cannot tell whether
                //  this is a namespace name or a class name
                //TODO : fix this so that special-casing is not needed
                if (path.ToLower(CultureInfo.InvariantCulture).Equals("root"))
                {
                    flags = flags | (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_TREAT_SINGLE_IDENT_AS_NS;
                }

                int status = wbemPath.SetText_(flags, path);

                if (status < 0)
                {
                    if ((status & 0xfffff000) == 0x80041000)
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(status);
                    }
                }
            }
        }
 public ManagementPath(string path)
 {
     if ((path != null) && (0 < path.Length))
     {
         this.wmiPath = this.CreateWbemPath(path);
     }
 }
Example #4
0
        private void CreateNewPath(string path)
        {
            wmiPath = (IWbemPath) new WbemDefPath();
            uint flags = (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_CREATE_ACCEPT_ALL;

            //For now we have to special-case the "root" namespace -
            //  this is because in the case of "root", the path parser cannot tell whether
            //  this is a namespace name or a class name
            //TODO : fix this so that special-casing is not needed
            if (path.ToLower().Equals("root"))
            {
                flags = flags | (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_TREAT_SINGLE_IDENT_AS_NS;
            }

            int status = (int)ManagementStatus.NoError;

            try {
                status = wmiPath.SetText_(flags, path);
            } catch (Exception e) {
                // BUGBUG : old throw new ArgumentOutOfRangeException ("path");  new:
                ManagementException.ThrowWithExtendedInfo(e);
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
        }
Example #5
0
 public ManagementPath(string path)
 {
     if (path != null && 0 < path.Length)
     {
         this.wmiPath = this.CreateWbemPath(path);
     }
 }
Example #6
0
        //Used to update the relative path when the user changes any key properties
        internal void UpdateRelativePath(string relPath)
        {
            if (relPath == null)
            {
                return;
            }

            //Get the server & namespace part from the existing path, and concatenate the given relPath.
            //NOTE : we need to do this because IWbemPath doesn't have a function to set the relative path alone...
            string newPath = string.Empty;
            string nsPath  = this.GetNamespacePath((int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY);

            if (nsPath.Length > 0)
            {
                newPath = string.Concat(nsPath, ":", relPath);
            }
            else
            {
                newPath = relPath;
            }

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

            this.SetWbemPath(newPath);
        }
Example #7
0
        private IWbemPath CreateWbemPath(string path)
        {
            IWbemPath wbemPath = (IWbemPath)MTAHelper.CreateInMTA(typeof(WbemDefPath));

            ManagementPath.SetWbemPath(wbemPath, path);
            return(wbemPath);
        }
Example #8
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);
        }
Example #9
0
        private IWbemPath CreateWbemPath(string path)
        {
            IWbemPath wbemPath = (IWbemPath)MTAHelper.CreateInMTA(typeof(WbemDefPath)); //new WbemDefPath();

            SetWbemPath(wbemPath, path);
            return(wbemPath);
        }
Example #10
0
        private static void SetWbemPath(IWbemPath wbemPath, string path)
        {
            if (null != wbemPath)
            {
                uint flags = (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_CREATE_ACCEPT_ALL;

                //For now we have to special-case the "root" namespace -
                //  this is because in the case of "root", the path parser cannot tell whether
                //  this is a namespace name or a class name
                if (string.Equals(path, "root", StringComparison.OrdinalIgnoreCase))
                {
                    flags |= (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_TREAT_SINGLE_IDENT_AS_NS;
                }

                int status = wbemPath.SetText_(flags, path);

                if (status < 0)
                {
                    if ((status & 0xfffff000) == 0x80041000)
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f());
                    }
                }
            }
        }
        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);
        }
Example #12
0
        //Used to update the relative path when the user changes any key properties
        internal void UpdateRelativePath(string relPath)
        {
            if (relPath == null)
            {
                return;
            }

            //Get the server & namespace part from the existing path, and concatenate the given relPath.
            //NOTE : we need to do this because IWbemPath doesn't have a function to set the relative path alone...
            string newPath = String.Empty;
            string nsPath  = this.NamespacePath;

            if (nsPath != String.Empty)
            {
                newPath = String.Concat(this.NamespacePath, ":", relPath);
            }
            else
            {
                newPath = relPath;
            }

            if (wmiPath == null)
            {
                wmiPath = (IWbemPath) new WbemDefPath();
            }

            //Set the flags for the SetText operation
            uint flags = (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_CREATE_ACCEPT_ALL;

            //Special-case the "root" namespace -
            //  this is because in the case of "root", the path parser cannot tell whether
            //  this is a namespace name or a class name
            //TODO : fix this so that special-casing is not needed
            if (newPath.ToLower().Equals("root"))
            {
                flags = flags | (uint)tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_TREAT_SINGLE_IDENT_AS_NS;
            }

            int status = (int)ManagementStatus.NoError;

            try
            {
                status = wmiPath.SetText_(flags, newPath);
            }
            catch (Exception e)
            {
                // BUGBUG : old throw new ArgumentOutOfRangeException ("path");  new:
                ManagementException.ThrowWithExtendedInfo(e);
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
        }
Example #13
0
        internal void SetRelativePath(string relPath)
        {
            ManagementPath newPath = new ManagementPath(relPath);

            newPath.NamespacePath = this.NamespacePath;
            newPath.Server        = this.Server;
            wmiPath = newPath.wmiPath;
        }
Example #14
0
        internal void SetRelativePath(string relPath)
        {
            ManagementPath managementPath = new ManagementPath(relPath);

            managementPath.NamespacePath = this.GetNamespacePath(8);
            managementPath.Server        = this.Server;
            this.wmiPath = managementPath.wmiPath;
        }
Example #15
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);
        }
Example #16
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);
        }
        internal void SetRelativePath(string relPath)
        {
            ManagementPath path = new ManagementPath(relPath)
            {
                NamespacePath = this.GetNamespacePath(8),
                Server        = this.Server
            };

            this.wmiPath = path.wmiPath;
        }
Example #18
0
        internal void SetRelativePath(string relPath)
        {
            // No need for isWbemPathShared here since internal SetRelativePath
            // always creates a new copy.
            ManagementPath newPath = new ManagementPath(relPath);

            newPath.NamespacePath = this.GetNamespacePath((int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY);
            newPath.Server        = this.Server;
            wmiPath = newPath.wmiPath;
        }
 private void SetWbemPath(string path)
 {
     if (this.wmiPath == null)
     {
         this.wmiPath = this.CreateWbemPath(path);
     }
     else
     {
         SetWbemPath(this.wmiPath, path);
     }
 }
Example #20
0
 private void SetWbemPath(string path)
 {
     // Test/utilize isWbemPathShared *only* on public + internal members!
     if (wmiPath == null)
     {
         wmiPath = CreateWbemPath(path);
     }
     else
     {
         SetWbemPath(wmiPath, path);
     }
 }
Example #21
0
 private void SetWbemPath(string path)
 {
     if (this.wmiPath != null)
     {
         ManagementPath.SetWbemPath(this.wmiPath, path);
         return;
     }
     else
     {
         this.wmiPath = this.CreateWbemPath(path);
         return;
     }
 }
 public void SetAsSingleton()
 {
     if (!this.IsClass && !this.IsInstance)
     {
         throw new ManagementException(ManagementStatus.InvalidOperation, null, null);
     }
     if (this.isWbemPathShared)
     {
         this.wmiPath          = this.CreateWbemPath(this.GetWbemPath());
         this.isWbemPathShared = false;
     }
     this.ClearKeys(true);
 }
        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);
        }
Example #24
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);
        }
Example #25
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);
        }
Example #26
0
 public void SetAsClass()
 {
     if (this.IsClass || this.IsInstance)
     {
         if (this.isWbemPathShared)
         {
             this.wmiPath          = this.CreateWbemPath(this.GetWbemPath());
             this.isWbemPathShared = false;
         }
         this.ClearKeys(false);
         return;
     }
     else
     {
         throw new ManagementException(ManagementStatus.InvalidOperation, null, null);
     }
 }
Example #27
0
        /// <summary>
        ///    <para> Sets the path as a new singleton object path. This means that it is a path to an instance but
        ///       there are no key values.</para>
        /// </summary>
        public void SetAsSingleton()
        {
            if (IsClass || IsInstance)
            {
                // Check if this IWbemPath is shared among multiple managed objects.
                // With this write, it will have to maintain its own copy.
                if (isWbemPathShared)
                {
                    wmiPath          = CreateWbemPath(this.GetWbemPath());
                    isWbemPathShared = false;
                }

                ClearKeys(true);
            }
            else
            {
                throw new ManagementException(ManagementStatus.InvalidOperation, null, null);
            }
        }
 internal void UpdateRelativePath(string relPath)
 {
     if (relPath != null)
     {
         string path          = string.Empty;
         string namespacePath = this.GetNamespacePath(8);
         if (namespacePath.Length > 0)
         {
             path = namespacePath + ":" + relPath;
         }
         else
         {
             path = relPath;
         }
         if (this.isWbemPathShared)
         {
             this.wmiPath          = this.CreateWbemPath(this.GetWbemPath());
             this.isWbemPathShared = false;
         }
         this.SetWbemPath(path);
     }
 }
 private static void SetWbemPath(IWbemPath wbemPath, string path)
 {
     if (wbemPath != null)
     {
         uint uMode = 4;
         if (string.Compare(path, "root", StringComparison.OrdinalIgnoreCase) == 0)
         {
             uMode |= 8;
         }
         int errorCode = wbemPath.SetText_(uMode, path);
         if (errorCode < 0)
         {
             if ((errorCode & 0xfffff000L) == 0x80041000L)
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
             }
             else
             {
                 Marshal.ThrowExceptionForHR(errorCode);
             }
         }
     }
 }
Example #30
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);
        }
Example #31
0
 private static void SetWbemPath(IWbemPath wbemPath, string path)
 {
     if (wbemPath != null)
     {
         uint num = 4;
         if (string.Compare(path, "root", StringComparison.OrdinalIgnoreCase) == 0)
         {
             num = num | 8;
         }
         int num1 = wbemPath.SetText_(num, path);
         if (num1 < 0)
         {
             if (((long)num1 & (long)-4096) != (long)-2147217408)
             {
                 Marshal.ThrowExceptionForHR(num1);
             }
             else
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus)num1);
                 return;
             }
         }
     }
 }
Example #32
0
		private static void SetWbemPath(IWbemPath wbemPath, string path)
		{
			if (wbemPath != null)
			{
				uint num = 4;
				if (string.Compare(path, "root", StringComparison.OrdinalIgnoreCase) == 0)
				{
					num = num | 8;
				}
				int num1 = wbemPath.SetText_(num, path);
				if (num1 < 0)
				{
					if (((long)num1 & (long)-4096) != (long)-2147217408)
					{
						Marshal.ThrowExceptionForHR(num1);
					}
					else
					{
						ManagementException.ThrowWithExtendedInfo((ManagementStatus)num1);
						return;
					}
				}
			}
		}
Example #33
0
		internal void UpdateRelativePath(string relPath)
		{
			string str;
			if (relPath != null)
			{
				string namespacePath = this.GetNamespacePath(8);
				if (namespacePath.Length <= 0)
				{
					str = relPath;
				}
				else
				{
					str = string.Concat(namespacePath, ":", relPath);
				}
				if (this.isWbemPathShared)
				{
					this.wmiPath = this.CreateWbemPath(this.GetWbemPath());
					this.isWbemPathShared = false;
				}
				this.SetWbemPath(str);
				return;
			}
			else
			{
				return;
			}
		}
 internal void SetRelativePath(string relPath)
 {
     ManagementPath path = new ManagementPath(relPath) {
         NamespacePath = this.GetNamespacePath(8),
         Server = this.Server
     };
     this.wmiPath = path.wmiPath;
 }
 private void SetWbemPath(string path)
 {
     // Test/utilize isWbemPathShared *only* on public + internal members!
     if (wmiPath == null)
         wmiPath = CreateWbemPath(path);
     else
         SetWbemPath(wmiPath, path);
 }
        private static void SetWbemPath(IWbemPath wbemPath, string path)
        {
            if (null != wbemPath)
            {
                uint flags = (uint) tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_CREATE_ACCEPT_ALL;

                //For now we have to special-case the "root" namespace - 
                //  this is because in the case of "root", the path parser cannot tell whether 
                //  this is a namespace name or a class name
                //
                if (String.Compare(path, "root", StringComparison.OrdinalIgnoreCase) == 0)
                    flags = flags | (uint) tag_WBEM_PATH_CREATE_FLAG.WBEMPATH_TREAT_SINGLE_IDENT_AS_NS;

                int status = wbemPath.SetText_(flags, path);

                if (status < 0)
                {
                    if ((status & 0xfffff000) == 0x80041000)
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                    else
                        Marshal.ThrowExceptionForHR(status);
                }
            }
        }
 internal void UpdateRelativePath(string relPath)
 {
     if (relPath != null)
     {
         string path = string.Empty;
         string namespacePath = this.GetNamespacePath(8);
         if (namespacePath.Length > 0)
         {
             path = namespacePath + ":" + relPath;
         }
         else
         {
             path = relPath;
         }
         if (this.isWbemPathShared)
         {
             this.wmiPath = this.CreateWbemPath(this.GetWbemPath());
             this.isWbemPathShared = false;
         }
         this.SetWbemPath(path);
     }
 }
Example #38
0
		internal void SetRelativePath(string relPath)
		{
			ManagementPath managementPath = new ManagementPath(relPath);
			managementPath.NamespacePath = this.GetNamespacePath(8);
			managementPath.Server = this.Server;
			this.wmiPath = managementPath.wmiPath;
		}
Example #39
0
		public void SetAsClass()
		{
			if (this.IsClass || this.IsInstance)
			{
				if (this.isWbemPathShared)
				{
					this.wmiPath = this.CreateWbemPath(this.GetWbemPath());
					this.isWbemPathShared = false;
				}
				this.ClearKeys(false);
				return;
			}
			else
			{
				throw new ManagementException(ManagementStatus.InvalidOperation, null, null);
			}
		}
        //Used to update the relative path when the user changes any key properties
        internal void UpdateRelativePath(string relPath)
        {
            if (relPath == null)
                return;

            //Get the server & namespace part from the existing path, and concatenate the given relPath.
            //NOTE : we need to do this because IWbemPath doesn't have a function to set the relative path alone...
            string newPath = String.Empty;
            string nsPath = this.GetNamespacePath((int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY);

            if (nsPath.Length>0 )
                newPath = String.Concat(nsPath, ":", relPath);
            else
                newPath = relPath;

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

            this.SetWbemPath(newPath);
        }
        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.Compare(nsOrg, nsNew, StringComparison.OrdinalIgnoreCase) != 0)
            {
                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)
                        {
                            string nSpace = new String('0', (int) uLen-1);
                            status = wmiPathTmp.GetNamespaceAt_(i, ref uLen, nSpace);
                            if (status >= 0)
                            {
                                status = wmiPath.SetNamespaceAt_(i, nSpace);
                                    
                                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)
                {
                    string serverNew = new String ('0', (int) uLen-1);
                    status = wmiPathTmp.GetServer_(ref uLen, serverNew);

                    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)
                        {
                            string serverOrg = new String('0', (int)uLen-1);
                            status = wmiPath.GetServer_(ref uLen, serverOrg);

                            if (status >= 0 && String.Compare(serverOrg, serverNew, StringComparison.OrdinalIgnoreCase) != 0)
                                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);
            }

            return nsNew;
        }
        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;
        }
 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;
 }
 public void SetAsSingleton()
 {
     if (!this.IsClass && !this.IsInstance)
     {
         throw new ManagementException(ManagementStatus.InvalidOperation, null, null);
     }
     if (this.isWbemPathShared)
     {
         this.wmiPath = this.CreateWbemPath(this.GetWbemPath());
         this.isWbemPathShared = false;
     }
     this.ClearKeys(true);
 }
Example #45
0
		private void SetWbemPath(string path)
		{
			if (this.wmiPath != null)
			{
				ManagementPath.SetWbemPath(this.wmiPath, path);
				return;
			}
			else
			{
				this.wmiPath = this.CreateWbemPath(path);
				return;
			}
		}
        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;
        }
Example #47
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;
		}
Example #48
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;
		}
 internal void SetRelativePath (string relPath)
 {
     // No need for isWbemPathShared here since internal SetRelativePath
     // always creates a new copy.
     ManagementPath newPath = new ManagementPath (relPath);
     newPath.NamespacePath = this.GetNamespacePath((int)tag_WBEM_GET_TEXT_FLAGS.WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY);
     newPath.Server = this.Server;
     wmiPath = newPath.wmiPath;
 }
        /// <summary>
        ///    <para> Sets the path as a new singleton object path. This means that it is a path to an instance but
        ///       there are no key values.</para>
        /// </summary>
        public void SetAsSingleton ()
        {
            if (IsClass || IsInstance)
            {
                // Check if this IWbemPath is shared among multiple managed objects.
                // With this write, it will have to maintain its own copy.
                if (isWbemPathShared)
                {
                    wmiPath = CreateWbemPath(this.GetWbemPath());
                    isWbemPathShared = false;
                }

                ClearKeys (true);
            }
            else
                throw new ManagementException (ManagementStatus.InvalidOperation, null, null);
        }
 private static void SetWbemPath(IWbemPath wbemPath, string path)
 {
     if (wbemPath != null)
     {
         uint uMode = 4;
         if (string.Compare(path, "root", StringComparison.OrdinalIgnoreCase) == 0)
         {
             uMode |= 8;
         }
         int errorCode = wbemPath.SetText_(uMode, path);
         if (errorCode < 0)
         {
             if ((errorCode & 0xfffff000L) == 0x80041000L)
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             }
             else
             {
                 Marshal.ThrowExceptionForHR(errorCode);
             }
         }
     }
 }
 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;
 }
 private void SetWbemPath(string path)
 {
     if (this.wmiPath == null)
     {
         this.wmiPath = this.CreateWbemPath(path);
     }
     else
     {
         SetWbemPath(this.wmiPath, path);
     }
 }
Example #54
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;
		}