/// <summary> /// <para>Adds a new <see cref='System.Management.PropertyData'/> with no assigned value.</para> /// </summary> /// <param name='propertyName'>The name of the property.</param> /// <param name='propertyType'>The CIM type of the property.</param> /// <param name='isArray'><see langword='true'/> to specify that the property is an array type; otherwise, <see langword='false'/>.</param> /// <remarks> /// <para> Properties can only be added to class definitions, not /// to instances. This method is only valid when invoked on a <see cref='System.Management.PropertyDataCollection'/> /// in /// a <see cref='System.Management.ManagementClass'/>.</para> /// </remarks> public void Add(string propertyName, CimType propertyType, bool isArray) { if (null == propertyName) { throw new ArgumentNullException(propertyName); } if (parent.GetType() == typeof(ManagementObject)) //can't add properties to instance { throw new InvalidOperationException(); } int wmiCimType = (int)propertyType; if (isArray) { wmiCimType |= (int)tag_CIMTYPE_ENUMERATION.CIM_FLAG_ARRAY; } object dummyObj = System.DBNull.Value; int status = parent.wbemObject.Put_(propertyName, 0, ref dummyObj, wmiCimType); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } }
/// <summary> /// <para>Removes a <see cref='System.Management.MethodData'/> from the <see cref='System.Management.MethodDataCollection'/>.</para> /// </summary> /// <param name='methodName'>The name of the method to remove from the collection.</param> /// <remarks> /// <para> /// Removing <see cref='System.Management.MethodData'/> objects from the <see cref='System.Management.MethodDataCollection'/> /// can only be done when the class has no /// instances. Any other case will result in an exception.</para> /// </remarks> public virtual void Remove(string methodName) { if (parent.GetType() == typeof(ManagementObject)) //can't remove methods from instance { throw new InvalidOperationException(); } int status = (int)ManagementStatus.Failed; try { status = parent.wbemObject.DeleteMethod_(methodName); } catch (COMException e) { ManagementException.ThrowWithExtendedInfo(e); } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } }
internal void Cancel() { if (null != stub) { #pragma warning disable CA2002 lock (this) #pragma warning restore CA2002 { if (null != stub) { int status = services.CancelAsyncCall_(stub); // Release prior to throwing an exception. ReleaseStub(); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } } } }
//****************************************************** //CompareTo //****************************************************** /// <summary> /// <para>Compares this object to another, based on specified options.</para> /// </summary> /// <param name='otherObject'>The object to which to compare this object. </param> /// <param name='settings'>Options on how to compare the objects. </param> /// <returns> /// <para><see langword='true'/> if the objects compared are equal /// according to the given options; otherwise, <see langword='false'/> /// .</para> /// </returns> public bool CompareTo(ManagementBaseObject otherObject, ComparisonSettings settings) { if (null == otherObject) { throw new ArgumentNullException(nameof(otherObject)); } bool result = false; if (null != wbemObject) { int status = (int)ManagementStatus.NoError; status = wbemObject.CompareTo_((int)settings, otherObject.wbemObject); if ((int)ManagementStatus.Different == status) { result = false; } else if ((int)ManagementStatus.NoError == status) { result = true; } else if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if (status < 0) { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } return(result); }
/// <summary> /// <para>Adds a new <see cref='System.Management.PropertyData'/> with the specified value and CIM type.</para> /// </summary> /// <param name='propertyName'>The name of the property.</param> /// <param name='propertyValue'>The value of the property (which can be null).</param> /// <param name='propertyType'>The CIM type of the property.</param> /// <remarks> /// <para> Properties can only be added to class definitions, not /// to instances. This method is only valid when invoked on a <see cref='System.Management.PropertyDataCollection'/> /// in /// a <see cref='System.Management.ManagementClass'/>.</para> /// </remarks> public void Add(string propertyName, object propertyValue, CimType propertyType) { if (null == propertyName) throw new ArgumentNullException(nameof(propertyName)); if (parent.GetType() == typeof(ManagementObject)) //can't add properties to instance throw new InvalidOperationException(); int wmiCimType = (int)propertyType; bool isArray = false; if ((null != propertyValue) && propertyValue.GetType().IsArray) { isArray = true; wmiCimType = (wmiCimType | (int)tag_CIMTYPE_ENUMERATION.CIM_FLAG_ARRAY); } object wmiValue = PropertyData.MapValueToWmiValue(propertyValue, propertyType, isArray); int status = parent.wbemObject.Put_(propertyName, 0, ref wmiValue, wmiCimType); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); else Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } }
/// <summary> /// Return the qualifier set associated with its type /// </summary> private IWbemQualifierSetFreeThreaded GetTypeQualifierSet(QualifierType qualifierSetType) { IWbemQualifierSetFreeThreaded qualifierSet = null; int status = qualifierSetType switch { QualifierType.ObjectQualifier => parent.wbemObject.GetQualifierSet_(out qualifierSet), QualifierType.PropertyQualifier => parent.wbemObject.GetPropertyQualifierSet_(propertyOrMethodName, out qualifierSet), QualifierType.MethodQualifier => parent.wbemObject.GetMethodQualifierSet_(propertyOrMethodName, out qualifierSet), _ => throw new ManagementException(ManagementStatus.Unexpected, null, null), // Is this the best fit error ?? }; if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } return(qualifierSet); }
internal PropertyDataEnumerator(ManagementBaseObject parent, bool isSystem) { this.parent = parent; propertyNames = null; index = -1; int flag; object qualVal = null; if (isSystem) { flag = (int)tag_WBEM_CONDITION_FLAG_TYPE.WBEM_FLAG_SYSTEM_ONLY; } else { flag = (int)tag_WBEM_CONDITION_FLAG_TYPE.WBEM_FLAG_NONSYSTEM_ONLY; } flag |= (int)tag_WBEM_CONDITION_FLAG_TYPE.WBEM_FLAG_ALWAYS; int status = parent.wbemObject.GetNames_(null, flag, ref qualVal, out propertyNames); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } }
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()); } } } }
//This private function is used to refresh the information from the Wmi object before returning the requested data private void RefreshQualifierInfo() { qualifierSet = null; int status = qualifierType switch { QualifierType.ObjectQualifier => parent.wbemObject.GetQualifierSet_(out qualifierSet), QualifierType.PropertyQualifier => parent.wbemObject.GetPropertyQualifierSet_(propertyOrMethodName, out qualifierSet), QualifierType.MethodQualifier => parent.wbemObject.GetMethodQualifierSet_(propertyOrMethodName, out qualifierSet), _ => throw new ManagementException(ManagementStatus.Unexpected, null, null), //is this the best fit error ?? }; if ((status & 0x80000000) == 0) //success { qualifierValue = null; //Make sure it's null so that we don't leak ! if (qualifierSet != null) { status = qualifierSet.Get_(qualifierName, 0, ref qualifierValue, ref qualifierFlavor); } } if ((status & 0xfffff000) == 0x80041000) //WMI error { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) //any failure { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } }
/// <summary> /// <para>Removes a <see cref='System.Management.PropertyData'/> from the <see cref='System.Management.PropertyDataCollection'/>.</para> /// </summary> /// <param name='propertyName'>The name of the property to be removed.</param> /// <remarks> /// <para> Properties can only be removed from class definitions, /// not from instances. This method is only valid when invoked on a property /// collection in a <see cref='System.Management.ManagementClass'/>.</para> /// </remarks> /// <example> /// <code lang='C#'>ManagementClass c = new ManagementClass("MyClass"); /// c.Properties.Remove("PropThatIDontWantOnThisClass"); /// </code> /// <code lang='VB'>Dim c As New ManagementClass("MyClass") /// c.Properties.Remove("PropThatIDontWantOnThisClass") /// </code> /// </example> public virtual void Remove(string propertyName) { // On instances, reset the property to the default value for the class. if (parent.GetType() == typeof(ManagementObject)) { ManagementClass cls = new ManagementClass(parent.ClassPath); parent.SetPropertyValue(propertyName, cls.GetPropertyValue(propertyName)); } else { int status = parent.wbemObject.Delete_(propertyName); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } }
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); }
/// <overload> /// <para>Copies the <see cref='System.Management.QualifierDataCollection'/> into an array.</para> /// </overload> /// <summary> /// <para> Copies the <see cref='System.Management.QualifierDataCollection'/> into an array.</para> /// </summary> /// <param name='array'>The array to which to copy the <see cref='System.Management.QualifierDataCollection'/>. </param> /// <param name='index'>The index from which to start copying. </param> public void CopyTo(Array array, int index) { if (null == array) { throw new ArgumentNullException(nameof(array)); } if ((index < array.GetLowerBound(0)) || (index > array.GetUpperBound(0))) { throw new ArgumentOutOfRangeException(nameof(index)); } // Get the names of the qualifiers string[] qualifierNames = null; IWbemQualifierSetFreeThreaded quals; try { quals = GetTypeQualifierSet(); } catch (ManagementException e) { // There are NO qualifiers on system properties, so we just return if (qualifierSetType == QualifierType.PropertyQualifier && e.ErrorCode == ManagementStatus.SystemProperty) { return; } else { throw; } } int status = quals.GetNames_(0, out qualifierNames); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } if ((index + qualifierNames.Length) > array.Length) { throw new ArgumentException(null, nameof(index)); } foreach (string qualifierName in qualifierNames) { array.SetValue(new QualifierData(parent, propertyOrMethodName, qualifierName, qualifierSetType), index++); } return; }
/// <overload> /// <para>Copies the <see cref='System.Management.PropertyDataCollection'/> into an array.</para> /// </overload> /// <summary> /// <para>Copies the <see cref='System.Management.PropertyDataCollection'/> into an array.</para> /// </summary> /// <param name='array'>The array to which to copy the <see cref='System.Management.PropertyDataCollection'/>. </param> /// <param name='index'>The index from which to start copying. </param> public void CopyTo(Array array, int index) { if (null == array) { throw new ArgumentNullException(nameof(array)); } if ((index < array.GetLowerBound(0)) || (index > array.GetUpperBound(0))) { throw new ArgumentOutOfRangeException(nameof(index)); } // Get the names of the properties string[] nameArray = null; object dummy = null; int flag = 0; if (isSystem) { flag |= (int)tag_WBEM_CONDITION_FLAG_TYPE.WBEM_FLAG_SYSTEM_ONLY; } else { flag |= (int)tag_WBEM_CONDITION_FLAG_TYPE.WBEM_FLAG_NONSYSTEM_ONLY; } flag |= (int)tag_WBEM_CONDITION_FLAG_TYPE.WBEM_FLAG_ALWAYS; int status = this.parent.wbemObject.GetNames_(null, flag, ref dummy, out nameArray); if (status >= 0) { if ((index + nameArray.Length) > array.Length) { throw new ArgumentException(null, nameof(index)); } foreach (string propertyName in nameArray) { array.SetValue(new PropertyData(parent, propertyName), index++); } } if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } 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, WmiNetUtilsHelper.GetErrorInfo_f()); } } } return(pathStr); }
//Internal constructor internal QualifierDataEnumerator(ManagementBaseObject parent, string propertyOrMethodName, QualifierType qualifierType) { this.parent = parent; this.propertyOrMethodName = propertyOrMethodName; this.qualifierType = qualifierType; this.qualifierNames = null; IWbemQualifierSetFreeThreaded qualifierSet = null; int status = (int)ManagementStatus.NoError; switch (qualifierType) { case QualifierType.ObjectQualifier: status = parent.wbemObject.GetQualifierSet_(out qualifierSet); break; case QualifierType.PropertyQualifier: status = parent.wbemObject.GetPropertyQualifierSet_(propertyOrMethodName, out qualifierSet); break; case QualifierType.MethodQualifier: status = parent.wbemObject.GetMethodQualifierSet_(propertyOrMethodName, out qualifierSet); break; default: throw new ManagementException(ManagementStatus.Unexpected, null, null); // Is this the best fit error ?? } // If we got an error code back, assume there are NO qualifiers for this object/property/method if (status < 0) { // qualifierNames = new String[] {}; } else { status = qualifierSet.GetNames_(0, out qualifierNames); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } }
//******************************************** //Start //******************************************** /// <summary> /// <para>Subscribes to events with the given query and delivers /// them, asynchronously, through the <see cref='System.Management.ManagementEventWatcher.EventArrived'/> event.</para> /// </summary> public void Start() { Initialize(); // Cancel any current event query Stop(); // Submit a new query SecurityHandler securityHandler = Scope.GetSecurityHandler(); IWbemServices wbemServices = scope.GetIWbemServices(); try { sink = new SinkForEventQuery(this, options.Context, wbemServices); if (sink.Status < 0) { Marshal.ThrowExceptionForHR(sink.Status, WmiNetUtilsHelper.GetErrorInfo_f()); } // For async event queries we should ensure 0 flags as this is // the only legal value int status = scope.GetSecuredIWbemServicesHandler(wbemServices).ExecNotificationQueryAsync_( query.QueryLanguage, query.QueryString, 0, options.GetContext(), sink.Stub); if (status < 0) { if (sink != null) { sink.ReleaseStub(); sink = null; } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } finally { securityHandler.Reset(); } }
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); }
/// <summary> /// <para>Removes a <see cref='System.Management.QualifierData'/> from the <see cref='System.Management.QualifierDataCollection'/> by name.</para> /// </summary> /// <param name='qualifierName'>The name of the <see cref='System.Management.QualifierData'/> to remove. </param> public virtual void Remove(string qualifierName) { int status = GetTypeQualifierSet().Delete_(qualifierName); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } }
//Internal constructor //Because WMI doesn't provide a "GetMethodNames" for methods similar to "GetNames" for properties, //We have to walk the methods list and cache the names here. //We lock to ensure that another thread doesn't interfere in the Begin/Next sequence. internal MethodDataEnumerator(ManagementObject parent) { this.parent = parent; methodNames = new ArrayList(); IWbemClassObjectFreeThreaded inP = null, outP = null; string tempMethodName; int status = (int)ManagementStatus.Failed; #pragma warning disable CA2002 lock (typeof(enumLock)) #pragma warning restore CA2002 { try { status = parent.wbemObject.BeginMethodEnumeration_(0); if (status >= 0) { tempMethodName = ""; // Condition primer to branch into the while loop. while (tempMethodName != null && status >= 0 && status != (int)tag_WBEMSTATUS.WBEM_S_NO_MORE_DATA) { tempMethodName = null; status = parent.wbemObject.NextMethod_(0, out tempMethodName, out inP, out outP); if (status >= 0 && status != (int)tag_WBEMSTATUS.WBEM_S_NO_MORE_DATA) { methodNames.Add(tempMethodName); } } parent.wbemObject.EndMethodEnumeration_(); // Ignore status. } } catch (COMException e) { ManagementException.ThrowWithExtendedInfo(e); } en = methodNames.GetEnumerator(); } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } }
//This private function is used to refresh the information from the Wmi object before returning the requested data private void RefreshPropertyInfo() { propertyValue = null; // Needed so we don't leak this in/out parameter... int status = parent.wbemObject.Get_(propertyName, 0, ref propertyValue, ref propertyType, ref propertyFlavor); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } }
public static IWbemClassObjectFreeThreaded GetErrorInfo() { IntPtr pErrorInfo = WmiNetUtilsHelper.GetErrorInfo_f(); if (IntPtr.Zero != pErrorInfo && new IntPtr(-1) != pErrorInfo) { IntPtr pIWbemClassObject; Marshal.QueryInterface(pErrorInfo, ref IWbemClassObjectFreeThreaded.IID_IWbemClassObject, out pIWbemClassObject); Marshal.Release(pErrorInfo); // The IWbemClassObjectFreeThreaded instance will own reference count on pIWbemClassObject if (pIWbemClassObject != IntPtr.Zero) { return(new IWbemClassObjectFreeThreaded(pIWbemClassObject)); } } return(null); }
/// <summary> /// <para>Returns a copy of the object.</para> /// </summary> /// <returns> /// <para>The new cloned object.</para> /// </returns> public virtual Object Clone() { IWbemClassObjectFreeThreaded theClone = null; int status = wbemObject.Clone_(out theClone); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } return(new ManagementBaseObject(theClone)); }
//This private function is used to refresh the information from the Wmi object before returning the requested data private void RefreshMethodInfo() { int status = (int)ManagementStatus.Failed; try { status = parent.wbemObject.GetMethod_(methodName, 0, out wmiInParams, out wmiOutParams); } catch (COMException e) { ManagementException.ThrowWithExtendedInfo(e); } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } }
private static bool _IsClass(IWbemClassObjectFreeThreaded wbemObject) { object val = null; int dummy1 = 0, dummy2 = 0; int status = wbemObject.Get_("__GENUS", 0, ref val, ref dummy1, ref dummy2); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } return((int)val == (int)tag_WBEM_GENUS_TYPE.WBEM_GENUS_CLASS); }
//internal factory /// <summary> /// Internal static "factory" method for making a new ManagementPath /// from the system property of a WMI object /// </summary> /// <param name="wbemObject">The WMI object whose __PATH property will /// be used to supply the returned object</param> internal static string GetManagementPath( IWbemClassObjectFreeThreaded wbemObject) { string path = null; int status = (int)ManagementStatus.Failed; if (null != wbemObject) { int dummy1 = 0, dummy2 = 0; object val = null; status = wbemObject.Get_("__PATH", 0, ref val, ref dummy1, ref dummy2); if ((status < 0) || (val == System.DBNull.Value)) { //try to get the relpath instead status = wbemObject.Get_("__RELPATH", 0, ref val, ref dummy1, ref dummy2); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } } if (System.DBNull.Value == val) { path = null; } else { path = (string)val; } } return(path); }
/// <summary> /// <para>Adds a <see cref='System.Management.QualifierData'/> to the <see cref='System.Management.QualifierDataCollection'/>. This overload /// specifies all property values for a <see cref='System.Management.QualifierData'/> object.</para> /// </summary> /// <param name='qualifierName'>The qualifier name. </param> /// <param name='qualifierValue'>The qualifier value. </param> /// <param name='isAmended'><see langword='true'/> to specify that this qualifier is amended (flavor); otherwise, <see langword='false'/>. </param> /// <param name='propagatesToInstance'><see langword='true'/> to propagate this qualifier to instances; otherwise, <see langword='false'/>. </param> /// <param name='propagatesToSubclass'><see langword='true'/> to propagate this qualifier to subclasses; otherwise, <see langword='false'/>. </param> /// <param name='isOverridable'><see langword='true'/> to specify that this qualifier's value is overridable in instances of subclasses; otherwise, <see langword='false'/>. </param> public virtual void Add(string qualifierName, object qualifierValue, bool isAmended, bool propagatesToInstance, bool propagatesToSubclass, bool isOverridable) { //Build the flavors bitmask and call the internal Add that takes a bitmask int qualFlavor = 0; if (isAmended) { qualFlavor = (qualFlavor | (int)tag_WBEM_FLAVOR_TYPE.WBEM_FLAVOR_AMENDED); } if (propagatesToInstance) { qualFlavor = (qualFlavor | (int)tag_WBEM_FLAVOR_TYPE.WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE); } if (propagatesToSubclass) { qualFlavor = (qualFlavor | (int)tag_WBEM_FLAVOR_TYPE.WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS); } // Note we use the NOT condition here since WBEM_FLAVOR_OVERRIDABLE == 0 if (!isOverridable) { qualFlavor = (qualFlavor | (int)tag_WBEM_FLAVOR_TYPE.WBEM_FLAVOR_NOT_OVERRIDABLE); } //Try to add the qualifier to the WMI object int status = GetTypeQualifierSet().Put_(qualifierName, ref qualifierValue, qualFlavor); if (status < 0) { if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } } }
private void ClearKeys(bool setAsSingleton) { // Test/utilize isWbemPathShared *only* on public + internal members! int status = (int)ManagementStatus.NoError; try { if (null != wmiPath) { IWbemPathKeyList keyList = null; status = wmiPath.GetKeyList_(out keyList); if (null != keyList) { status = keyList.RemoveAllKeys_(0); if ((status & 0x80000000) == 0) { sbyte bSingleton = (setAsSingleton) ? (sbyte)(-1) : (sbyte)0; status = keyList.MakeSingleton_(bSingleton); FireIdentifierChanged(); } } } } catch (COMException e) { ManagementException.ThrowWithExtendedInfo(e); } if ((status & 0xfffff000) == 0x80041000) { ManagementException.ThrowWithExtendedInfo((ManagementStatus)status); } else if ((status & 0x80000000) != 0) { Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f()); } }