public void SetStatus(
            int flags,
            int hResult,
            String message,
            IntPtr pErrObj)
        {
            IWbemClassObjectFreeThreaded errObj = null;

            if (pErrObj != IntPtr.Zero)
            {
                Marshal.AddRef(pErrObj);
                errObj = new IWbemClassObjectFreeThreaded(pErrObj);
            }
            // TODO: errObj never used

            try {
                if (null != eventWatcher)
                {
                    // Fire Stopped event
                    eventWatcher.FireStopped(new StoppedEventArgs(context, hResult));

                    // Unhook the parent watcher
                    eventWatcher = null;
                }

                ReleaseStub();
            } catch {}
        }
        private void DeserializeFromBlob(byte[] rg)
        {
            IntPtr  zero   = IntPtr.Zero;
            IStream stream = null;

            try
            {
                this.pWbemClassObject = IntPtr.Zero;
                zero = Marshal.AllocHGlobal((int)rg.Length);
                Marshal.Copy(rg, 0, zero, (int)rg.Length);
                stream = IWbemClassObjectFreeThreaded.CreateStreamOnHGlobal(zero, 0);
                this.pWbemClassObject = IWbemClassObjectFreeThreaded.CoUnmarshalInterface(stream, ref IWbemClassObjectFreeThreaded.IID_IWbemClassObject);
            }
            finally
            {
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                }
                if (zero != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(zero);
                }
            }
        }
示例#3
0
        //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 ManagementPath GetManagementPath(
            IWbemClassObjectFreeThreaded wbemObject)
        {
            ManagementPath 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 & 0xfffff000) == 0x80041000)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                }
                else if ((status & 0x80000000) != 0)
                {
                    Marshal.ThrowExceptionForHR(status);
                }
                if (System.DBNull.Value != val)
                {
                    path = new ManagementPath((string)val);
                }
            }

            return(path);
        }
示例#4
0
        public ManagementObject CreateInstance()
        {
            ManagementObject managementObject = null;

            if (base.PutButNotGot)
            {
                base.Get();
                base.PutButNotGot = false;
            }
            IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = null;
            int num = base.wbemObject.SpawnInstance_(0, out wbemClassObjectFreeThreaded);

            if (num < 0)
            {
                if (((long)num & (long)-4096) != (long)-2147217408)
                {
                    Marshal.ThrowExceptionForHR(num);
                }
                else
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
                }
            }
            else
            {
                managementObject = ManagementObject.GetManagementObject(wbemClassObjectFreeThreaded, base.Scope);
            }
            return(managementObject);
        }
        public int NextMethod_(int lFlags, out string pstrName, out IWbemClassObjectFreeThreaded ppInSignature, out IWbemClassObjectFreeThreaded ppOutSignature)
        {
            IntPtr intPtr;
            IntPtr intPtr1;

            if (this.pWbemClassObject != IntPtr.Zero)
            {
                int num = WmiNetUtilsHelper.NextMethod_f(23, this.pWbemClassObject, lFlags, out pstrName, out intPtr, out intPtr1);
                ppInSignature  = null;
                ppOutSignature = null;
                if (num >= 0)
                {
                    if (intPtr != IntPtr.Zero)
                    {
                        ppInSignature = new IWbemClassObjectFreeThreaded(intPtr);
                    }
                    if (intPtr1 != IntPtr.Zero)
                    {
                        ppOutSignature = new IWbemClassObjectFreeThreaded(intPtr1);
                    }
                }
                GC.KeepAlive(this);
                return(num);
            }
            else
            {
                throw new ObjectDisposedException(IWbemClassObjectFreeThreaded.name);
            }
        }
        private byte[] SerializeToBlob()
        {
            System.Runtime.InteropServices.ComTypes.STATSTG sTATSTG;
            byte[]  numArray = null;
            IStream stream   = null;
            IntPtr  zero     = IntPtr.Zero;

            try
            {
                stream = IWbemClassObjectFreeThreaded.CreateStreamOnHGlobal(IntPtr.Zero, 1);
                IWbemClassObjectFreeThreaded.CoMarshalInterface(stream, ref IWbemClassObjectFreeThreaded.IID_IWbemClassObject, this.pWbemClassObject, 2, IntPtr.Zero, 2);
                stream.Stat(out sTATSTG, 0);
                numArray = new byte[sTATSTG.cbSize];
                zero     = IWbemClassObjectFreeThreaded.GlobalLock(IWbemClassObjectFreeThreaded.GetHGlobalFromStream(stream));
                Marshal.Copy(zero, numArray, 0, (int)sTATSTG.cbSize);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    IWbemClassObjectFreeThreaded.GlobalUnlock(zero);
                }
                if (stream != null)
                {
                    Marshal.ReleaseComObject(stream);
                }
            }
            GC.KeepAlive(this);
            return(numArray);
        }
示例#7
0
        internal static void ThrowWithExtendedInfo(Exception e)
        {
            ManagementBaseObject errObj = null;
            string msg = null;

            //Try to get extended error info first, and save in errorObject member
            IWbemClassObjectFreeThreaded obj = WbemErrorInfo.GetErrorInfo();

            if (obj != null)
            {
                errObj = new ManagementBaseObject(obj);
            }

            //If the error code is not a WMI one and there's an extended error object available, stick the message
            //from the extended error object in.
            if (((msg = GetMessage(e)) == null) && (errObj != null))
            {
                try
                {
                    msg = (string)errObj["Description"];
                }
                catch {}
            }

            throw new ManagementException(e, msg, errObj);
        }
 internal ManagementBaseObject(IWbemClassObjectFreeThreaded wbemObject)
 {
     this.wbemObject = wbemObject;
     this.properties = null;
     this.systemProperties = null;
     this.qualifiers = null;
 }
示例#9
0
        /// <summary>
        ///    <para>Returns a copy of the object.</para>
        /// </summary>
        /// <returns>
        ///    <para>The new cloned object.</para>
        /// </returns>
        public virtual Object Clone()
        {
            //
            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
            // its getter.
            //
            // Initialize ( ) ;
            IWbemClassObjectFreeThreaded theClone = null;

            int status = wbemObject.Clone_(out theClone);

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

            return(new ManagementBaseObject(theClone));
        }
 //Constructor
 internal ManagementBaseObject(IWbemClassObjectFreeThreaded wbemObject)
 {
     this.wbemObject  = wbemObject;
     properties       = null;
     systemProperties = null;
     qualifiers       = null;
 }
        public int GetMethod_(string wszName, int lFlags, out IWbemClassObjectFreeThreaded ppInSignature, out IWbemClassObjectFreeThreaded ppOutSignature)
        {
            IntPtr ptr;
            IntPtr ptr2;

            if (this.pWbemClassObject == IntPtr.Zero)
            {
                throw new ObjectDisposedException(name);
            }
            int num = WmiNetUtilsHelper.GetMethod_f(0x13, this.pWbemClassObject, wszName, lFlags, out ptr, out ptr2);

            ppInSignature  = null;
            ppOutSignature = null;
            if (num >= 0)
            {
                if (ptr != IntPtr.Zero)
                {
                    ppInSignature = new IWbemClassObjectFreeThreaded(ptr);
                }
                if (ptr2 != IntPtr.Zero)
                {
                    ppOutSignature = new IWbemClassObjectFreeThreaded(ptr2);
                }
            }
            GC.KeepAlive(this);
            return(num);
        }
示例#12
0
        //This variant takes the full information, i.e. the method name and in & out param objects
        /// <summary>
        /// <para>Adds a <see cref='System.Management.MethodData'/> to the <see cref='System.Management.MethodDataCollection'/>. This overload will add a new method with the
        ///    specified parameter objects to the collection.</para>
        /// </summary>
        /// <param name='methodName'>The name of the method to add.</param>
        /// <param name=' inParams'>The <see cref='System.Management.ManagementBaseObject'/> holding the input parameters to the method.</param>
        /// <param name=' outParams'>The <see cref='System.Management.ManagementBaseObject'/> holding the output parameters to the method.</param>
        /// <remarks>
        /// <para> Adding <see cref='System.Management.MethodData'/> objects to 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 Add(string methodName, ManagementBaseObject inParams, ManagementBaseObject outParams)
        {
            IWbemClassObjectFreeThreaded wbemIn = null, wbemOut = null;

            if (parent.GetType() == typeof(ManagementObject))             //can't add methods to instance
            {
                throw new InvalidOperationException();
            }

            if (inParams != null)
            {
                wbemIn = inParams.wbemObject;
            }
            if (outParams != null)
            {
                wbemOut = outParams.wbemObject;
            }

            int status = (int)ManagementStatus.Failed;

            try {
                status = parent.wbemObject.PutMethod_(methodName, 0, wbemIn, wbemOut);
            } catch (Exception e) {
                ManagementException.ThrowWithExtendedInfo(e);
            }

            if ((status & 0xfffff000) == 0x80041000)
            {
                ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
            }
            else if ((status & 0x80000000) != 0)
            {
                Marshal.ThrowExceptionForHR(status);
            }
        }
        public void SetStatus(
            int flags,
            int hResult,
            String message,
            IntPtr pErrObj)
        {
#if TODO_ERROBJ_NEVER_USED
            IWbemClassObjectFreeThreaded errObj = null;
            if (pErrObj != IntPtr.Zero)
            {
                Marshal.AddRef(pErrObj);
                errObj = new IWbemClassObjectFreeThreaded(pErrObj);
            }
#endif // TODO_ERROBJ_NEVER_USED

            try
            {
                // Fire Stopped event
                eventWatcher.FireStopped(new StoppedEventArgs(context, hResult));

                //This handles cases in which WMI calls SetStatus to indicate a problem, for example
                //a queue overflow due to slow client processing.
                //Currently we just cancel the subscription in this case.
                // BUG# 97657 - When you cancel a call with CancelAsyncCall, on Windows 2000,
                // you get a SetStatus with WBEM_E_CALL_CANCELLED.  On Windows XP, you get
                // a set status with WBEM_S_OPERATION_CANCELLED!!!
                if (hResult != (int)tag_WBEMSTATUS.WBEM_E_CALL_CANCELLED &&
                    hResult != (int)tag_WBEMSTATUS.WBEM_S_OPERATION_CANCELLED)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(Cancel2));                    // Cancel(); // BUG#118550 - On Win2k, we get a deadlock if we do a Cancel within a SetStatus
                }
            }
            catch {}
        }
        //internal IWbemServices GetIWbemServices () {
        //	return scope.GetIWbemServices ();
        //}

        //internal ConnectionOptions Connection {
        //	get { return scope.Connection; }
        //}

        //Constructor
        internal ManagementObjectCollection(
            ManagementScope scope,
            EnumerationOptions options,
            IEnumWbemClassObject enumWbem)
        {
            if (null != options)
            {
                this.options = (EnumerationOptions)options.Clone();
            }
            else
            {
                this.options = new EnumerationOptions();
            }

            if (null != scope)
            {
                this.scope = (ManagementScope)scope.Clone();
            }
            else
            {
                this.scope = ManagementScope._Clone(null);
            }

            this.enumWbem = enumWbem;
            current       = null;
            firstEnum     = new FirstEnum();
        }
        internal static string GetManagementPath(IWbemClassObjectFreeThreaded wbemObject)
        {
            string str       = null;
            int    errorCode = -2147217407;

            if (wbemObject == null)
            {
                return(str);
            }
            int    pType    = 0;
            int    plFlavor = 0;
            object pVal     = null;

            if ((wbemObject.Get_("__PATH", 0, ref pVal, ref pType, ref plFlavor) < 0) || (pVal == DBNull.Value))
            {
                errorCode = wbemObject.Get_("__RELPATH", 0, ref pVal, ref pType, ref plFlavor);
                if (errorCode < 0)
                {
                    if ((errorCode & 0xfffff000L) == 0x80041000L)
                    {
                        ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                    }
                    else
                    {
                        Marshal.ThrowExceptionForHR(errorCode);
                    }
                }
            }
            if (DBNull.Value == pVal)
            {
                return(null);
            }
            return((string)pVal);
        }
示例#16
0
        public void SetStatus(int flags, int hResult, string message, IntPtr pErrorObj)
        {
            IWbemClassObjectFreeThreaded wbemObject = null;

            if (pErrorObj != IntPtr.Zero)
            {
                Marshal.AddRef(pErrorObj);
                wbemObject = new IWbemClassObjectFreeThreaded(pErrorObj);
            }
            try
            {
                if (flags == 0)
                {
                    if (this.path != null)
                    {
                        if (this.className == null)
                        {
                            this.path.RelativePath = message;
                        }
                        else
                        {
                            this.path.RelativePath = this.className;
                        }
                        if (this.InternalObjectPut != null)
                        {
                            try
                            {
                                InternalObjectPutEventArgs e = new InternalObjectPutEventArgs(this.path);
                                this.InternalObjectPut(this, e);
                            }
                            catch
                            {
                            }
                        }
                        ObjectPutEventArgs args2 = new ObjectPutEventArgs(this.context, this.path);
                        this.watcher.FireObjectPut(args2);
                    }
                    CompletedEventArgs args3 = null;
                    if (wbemObject != null)
                    {
                        args3 = new CompletedEventArgs(this.context, hResult, new ManagementBaseObject(wbemObject));
                    }
                    else
                    {
                        args3 = new CompletedEventArgs(this.context, hResult, null);
                    }
                    this.watcher.FireCompleted(args3);
                    this.watcher.RemoveSink(this);
                }
                else if ((flags & 2) != 0)
                {
                    ProgressEventArgs args = new ProgressEventArgs(this.context, (hResult & -65536) >> 0x10, hResult & 0xffff, message);
                    this.watcher.FireProgress(args);
                }
            }
            catch
            {
            }
        }
 internal static ManagementBaseObject GetBaseObject(IWbemClassObjectFreeThreaded wbemObject, ManagementScope scope)
 {
     if (_IsClass(wbemObject))
     {
         return(ManagementClass.GetManagementClass(wbemObject, scope));
     }
     return(ManagementObject.GetManagementObject(wbemObject, scope));
 }
示例#18
0
        /// <summary>
        /// ICollection method to copy collection into array
        /// </summary>
        /// <param name="array"> Array to copy to </param>
        /// <param name="index"> Index to start from </param>
        public void CopyTo(Array array, Int32 index)
        {
            if (null == array)
            {
                throw new ArgumentNullException("array");
            }

            if ((index < array.GetLowerBound(0)) || (index > array.GetUpperBound(0)))
            {
                throw new ArgumentOutOfRangeException("index");
            }

            // Get the names of the properties
            string[] nameArray = null;
            IWbemClassObjectFreeThreaded wbemObject = this.parent.wbemObject;
            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 = wbemObject.GetNames_(null, flag, ref dummy, out nameArray);

            if (status >= 0)
            {
                if ((index + nameArray.Length) > array.Length)
                {
                    throw new ArgumentException("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);
                }
            }

            return;
        }
 internal int ExecMethod_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObjectFreeThreaded pInParams, ref IWbemClassObjectFreeThreaded ppOutParams, IntPtr ppCallResult)
 {
     int num = -2147217407;
     if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero))
     {
         num = this.pWbemServiecsSecurityHelper.ExecMethod_(strObjectPath, strMethodName, lFlags, pCtx, (IntPtr) pInParams, out ppOutParams, ppCallResult);
     }
     return num;
 }
示例#20
0
        public ManagementClass Derive(string newClassName)
        {
            ManagementClass managementClass = null;

            if (newClassName != null)
            {
                ManagementPath managementPath = new ManagementPath();
                try
                {
                    managementPath.ClassName = newClassName;
                }
                catch
                {
                    throw new ArgumentOutOfRangeException("newClassName");
                }
                if (managementPath.IsClass)
                {
                    if (base.PutButNotGot)
                    {
                        base.Get();
                        base.PutButNotGot = false;
                    }
                    IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = null;
                    int num = base.wbemObject.SpawnDerivedClass_(0, out wbemClassObjectFreeThreaded);
                    if (num >= 0)
                    {
                        object obj1 = newClassName;
                        num = wbemClassObjectFreeThreaded.Put_("__CLASS", 0, ref obj1, 0);
                        if (num >= 0)
                        {
                            managementClass = ManagementClass.GetManagementClass(wbemClassObjectFreeThreaded, this);
                        }
                    }
                    if (num < 0)
                    {
                        if (((long)num & (long)-4096) != (long)-2147217408)
                        {
                            Marshal.ThrowExceptionForHR(num);
                        }
                        else
                        {
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
                        }
                    }
                    return(managementClass);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("newClassName");
                }
            }
            else
            {
                throw new ArgumentNullException("newClassName");
            }
        }
 public void Dispose()
 {
     if (this._wbemObject != null)
     {
         this._wbemObject.Dispose();
         this._wbemObject = null;
     }
     base.Dispose();
     GC.SuppressFinalize(this);
 }
 public int CompareTo_(int lFlags, IWbemClassObjectFreeThreaded pCompareTo)
 {
     if (this.pWbemClassObject == IntPtr.Zero)
     {
         throw new ObjectDisposedException(name);
     }
     int num = WmiNetUtilsHelper.CompareTo_f(0x10, this.pWbemClassObject, lFlags, pCompareTo.pWbemClassObject);
     GC.KeepAlive(this);
     return num;
 }
 public new void Dispose()
 {
     if (_wbemObject != null)
     {
         _wbemObject.Dispose();
         _wbemObject = null;
     }
     base.Dispose();
     GC.SuppressFinalize(this);
 }
示例#24
0
        internal int PutInstance_(IWbemClassObjectFreeThreaded pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult)
        {
            int num = -2147217407;

            if (this.scope != null)
            {
                num = WmiNetUtilsHelper.PutInstanceWmi_f((IntPtr)pInst, lFlags, pCtx, ppCallResult, (int)this.scope.Options.Authentication, (int)this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority);
            }
            return(num);
        }
示例#25
0
        internal int GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, ref IWbemClassObjectFreeThreaded ppObject, IntPtr ppCallResult)
        {
            int num = -2147217407;

            if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero))
            {
                num = this.pWbemServiecsSecurityHelper.GetObject_(strObjectPath, lFlags, pCtx, out ppObject, ppCallResult);
            }
            return(num);
        }
示例#26
0
        public virtual void Indicate(IntPtr pIWbemClassObject)
        {
            Marshal.AddRef(pIWbemClassObject);
            IWbemClassObjectFreeThreaded obj = new IWbemClassObjectFreeThreaded(pIWbemClassObject);

            try {
                ObjectReadyEventArgs args = new ObjectReadyEventArgs(context,
                                                                     ManagementBaseObject.GetBaseObject(obj, scope));
                watcher.FireObjectReady(args);
            } catch {}
        }
        public int PutMethod_(string wszName, int lFlags, IWbemClassObjectFreeThreaded pInSignature, IWbemClassObjectFreeThreaded pOutSignature)
        {
            if (this.pWbemClassObject == IntPtr.Zero)
            {
                throw new ObjectDisposedException(name);
            }
            int num = WmiNetUtilsHelper.PutMethod_f(20, this.pWbemClassObject, wszName, lFlags, (IntPtr)pInSignature, (IntPtr)pOutSignature);

            GC.KeepAlive(this);
            return(num);
        }
示例#28
0
		public int ExecMethod_ (string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IntPtr pInParams, out IWbemClassObjectFreeThreaded ppOutParams, IntPtr ppCallResult)
		{
			string strQuery = QueryParser.GetQueryFromPath (strObjectPath);
			var items = WMIDatabaseFactory.Get (_currentNamespace, strQuery);
			ppOutParams = null;
			foreach (var obj in items) {
				var intPtr = MarshalWbemObject.GetInstance(null).MarshalManagedToNative (obj);
				ppOutParams = new IWbemClassObjectFreeThreaded(intPtr);
			}
			return 0;
		}
        public int CompareTo_(int lFlags, IWbemClassObjectFreeThreaded pCompareTo)
        {
            if (this.pWbemClassObject == IntPtr.Zero)
            {
                throw new ObjectDisposedException(name);
            }
            int num = WmiNetUtilsHelper.CompareTo_f(0x10, this.pWbemClassObject, lFlags, pCompareTo.pWbemClassObject);

            GC.KeepAlive(this);
            return(num);
        }
示例#30
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref='System.Management.ManagementBaseObject'/> class that is serializable.</para>
 /// </summary>
 /// <param name='info'>The <see cref='System.Runtime.Serialization.SerializationInfo'/> to populate with data.</param>
 /// <param name='context'>The destination (see <see cref='System.Runtime.Serialization.StreamingContext'/> ) for this serialization.</param>
 protected ManagementBaseObject(SerializationInfo info, StreamingContext context)
 {
     wbemObject = info.GetValue("wbemObject", typeof(IWbemClassObjectFreeThreaded)) as IWbemClassObjectFreeThreaded;
     if (null == wbemObject)
     {
         throw new SerializationException();
     }
     properties       = null;
     systemProperties = null;
     qualifiers       = null;
 }
 protected ManagementBaseObject(SerializationInfo info, StreamingContext context)
 {
     this._wbemObject = info.GetValue("wbemObject", typeof(IWbemClassObjectFreeThreaded)) as IWbemClassObjectFreeThreaded;
     if (this._wbemObject == null)
     {
         throw new SerializationException();
     }
     this.properties = null;
     this.systemProperties = null;
     this.qualifiers = null;
 }
示例#32
0
        public override void Indicate(IntPtr pIWbemClassObject)
        {
            Marshal.AddRef(pIWbemClassObject);
            IWbemClassObjectFreeThreaded obj = new IWbemClassObjectFreeThreaded(pIWbemClassObject);

            if (null != managementObject)
            {
                try {
                    managementObject.wbemObject = obj;
                } catch {}
            }
        }
示例#33
0
        internal static ManagementClass GetManagementClass(IWbemClassObjectFreeThreaded wbemObject, ManagementScope scope)
        {
            ManagementClass managementClass = new ManagementClass();

            managementClass.path = new ManagementPath(ManagementPath.GetManagementPath(wbemObject));
            if (scope != null)
            {
                managementClass.scope = ManagementScope._Clone(scope);
            }
            managementClass.wbemObject = wbemObject;
            return(managementClass);
        }
示例#34
0
        public int ExecMethod_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IntPtr pInParams, out IWbemClassObjectFreeThreaded ppOutParams, IntPtr ppCallResult)
        {
            string strQuery = QueryParser.GetQueryFromPath(strObjectPath);
            var    items    = WMIDatabaseFactory.Get(_currentNamespace, strQuery);

            ppOutParams = null;
            foreach (var obj in items)
            {
                var intPtr = MarshalWbemObject.GetInstance(null).MarshalManagedToNative(obj);
                ppOutParams = new IWbemClassObjectFreeThreaded(intPtr);
            }
            return(0);
        }
 public void Indicate(IntPtr pWbemClassObject)
 {
     Marshal.AddRef(pWbemClassObject);
     IWbemClassObjectFreeThreaded wbemObject = new IWbemClassObjectFreeThreaded(pWbemClassObject);
     try
     {
         EventArrivedEventArgs args = new EventArrivedEventArgs(this.context, new ManagementBaseObject(wbemObject));
         this.eventWatcher.FireEventArrived(args);
     }
     catch
     {
     }
 }
示例#36
0
        internal static ManagementClass GetManagementClass(IWbemClassObjectFreeThreaded wbemObject, ManagementScope scope)
        {
            ManagementClass class2 = new ManagementClass {
                path = new ManagementPath(ManagementPath.GetManagementPath(wbemObject))
            };

            if (scope != null)
            {
                class2.scope = ManagementScope._Clone(scope);
            }
            class2.wbemObject = wbemObject;
            return(class2);
        }
		/// <summary>
		/// Internal factory for classes, used when deriving a class
		/// or cloning a class. For these purposes we always mark
		/// the class as "bound".
		/// </summary>
		/// <param name="wbemObject">The underlying WMI object</param>
		/// <param name="mgObj">Seed class from which we will get initialization info</param>
		internal static ManagementClass GetManagementClass(
			IWbemClassObjectFreeThreaded wbemObject,
			ManagementClass mgObj)
		{ 
			ManagementClass newClass = new ManagementClass();
            newClass.wbemObject = wbemObject;

			if (null != mgObj)
			{
				newClass.scope = ManagementScope._Clone(mgObj.scope);

				ManagementPath objPath = mgObj.Path;

				if (null != objPath)
					newClass.path = ManagementPath._Clone(objPath);

				// Ensure we have our class name in the path
				object className = null;
				int dummy = 0;

				int status = wbemObject.Get_("__CLASS", 0, ref className, ref dummy, ref dummy);

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

				if (className != System.DBNull.Value)
					newClass.path.internalClassName = (string)className;

				ObjectGetOptions options = mgObj.Options;
				if (null != options)
					newClass.options = ObjectGetOptions._Clone(options);

				// Finally we ensure that this object is marked as bound.
				// We do this as a last step since setting certain properties
				// (Options, Path and Scope) would mark it as unbound
				//
				// ***
				// *	Changed isBound flag to wbemObject==null check.
				// *	newClass.IsBound = true;
				// ***
			}

			return newClass;
		}
示例#38
0
		public override void Indicate(IntPtr pIWbemClassObject)
		{
			Marshal.AddRef(pIWbemClassObject);
			IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded(pIWbemClassObject);
			if (this.managementObject != null)
			{
				try
				{
					this.managementObject.wbemObject = wbemClassObjectFreeThreaded;
				}
				catch
				{
				}
			}
		}
 public int Clone_(out IWbemClassObjectFreeThreaded ppCopy)
 {
     IntPtr ptr;
     if (this.pWbemClassObject == IntPtr.Zero)
     {
         throw new ObjectDisposedException(name);
     }
     int num = WmiNetUtilsHelper.Clone_f(12, this.pWbemClassObject, out ptr);
     if (num < 0)
     {
         ppCopy = null;
     }
     else
     {
         ppCopy = new IWbemClassObjectFreeThreaded(ptr);
     }
     GC.KeepAlive(this);
     return num;
 }
 private static bool _IsClass(IWbemClassObjectFreeThreaded wbemObject)
 {
     object pVal = null;
     int pType = 0;
     int plFlavor = 0;
     int errorCode = wbemObject.Get_("__GENUS", 0, ref pVal, ref pType, ref plFlavor);
     if (errorCode < 0)
     {
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
         }
         else
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
     return (((int) pVal) == 1);
 }
		public int Clone_(out IWbemClassObjectFreeThreaded ppCopy)
		{
			IntPtr intPtr;
			if (this.pWbemClassObject != IntPtr.Zero)
			{
				int cloneF = WmiNetUtilsHelper.Clone_f(12, this.pWbemClassObject, out intPtr);
				if (cloneF >= 0)
				{
					ppCopy = new IWbemClassObjectFreeThreaded(intPtr);
				}
				else
				{
					ppCopy = null;
				}
				GC.KeepAlive(this);
				return cloneF;
			}
			else
			{
				throw new ObjectDisposedException(IWbemClassObjectFreeThreaded.name);
			}
		}
 internal static ManagementBaseObject GetBaseObject(IWbemClassObjectFreeThreaded wbemObject, ManagementScope scope)
 {
     if (_IsClass(wbemObject))
     {
         return ManagementClass.GetManagementClass(wbemObject, scope);
     }
     return ManagementObject.GetManagementObject(wbemObject, scope);
 }
 public void Dispose()
 {
     if (this._wbemObject != null)
     {
         this._wbemObject.Dispose();
         this._wbemObject = null;
     }
     base.Dispose();
     GC.SuppressFinalize(this);
 }
示例#44
0
		public virtual void Indicate(IntPtr pIWbemClassObject)
		{
			Marshal.AddRef(pIWbemClassObject);
			IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded(pIWbemClassObject);
			try
			{
				ObjectReadyEventArgs objectReadyEventArg = new ObjectReadyEventArgs(this.context, ManagementBaseObject.GetBaseObject(wbemClassObjectFreeThreaded, this.scope));
				this.watcher.FireObjectReady(objectReadyEventArg);
			}
			catch
			{
			}
		}
示例#45
0
		public void SetStatus(int flags, int hResult, string message, IntPtr pErrorObj)
		{
			CompletedEventArgs completedEventArg;
			IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = null;
			if (pErrorObj != IntPtr.Zero)
			{
				Marshal.AddRef(pErrorObj);
				wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded(pErrorObj);
			}
			try
			{
				if (flags != 0)
				{
					if ((flags & 2) != 0)
					{
						ProgressEventArgs progressEventArg = new ProgressEventArgs(this.context, (hResult & -65536) >> 16, hResult & 0xffff, message);
						this.watcher.FireProgress(progressEventArg);
					}
				}
				else
				{
					if (this.path != null)
					{
						if (this.className != null)
						{
							this.path.RelativePath = this.className;
						}
						else
						{
							this.path.RelativePath = message;
						}
						if (this.InternalObjectPut != null)
						{
							try
							{
								InternalObjectPutEventArgs internalObjectPutEventArg = new InternalObjectPutEventArgs(this.path);
								this.InternalObjectPut(this, internalObjectPutEventArg);
							}
							catch
							{
							}
						}
						ObjectPutEventArgs objectPutEventArg = new ObjectPutEventArgs(this.context, this.path);
						this.watcher.FireObjectPut(objectPutEventArg);
					}
					if (wbemClassObjectFreeThreaded == null)
					{
						completedEventArg = new CompletedEventArgs(this.context, hResult, null);
					}
					else
					{
						completedEventArg = new CompletedEventArgs(this.context, hResult, new ManagementBaseObject(wbemClassObjectFreeThreaded));
					}
					this.watcher.FireCompleted(completedEventArg);
					this.watcher.RemoveSink(this);
				}
			}
			catch
			{
			}
		}
 internal int PutInstance_(IWbemClassObjectFreeThreaded pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult)
 {
     int num = -2147217407;
     if (this.scope != null)
     {
         num = WmiNetUtilsHelper.PutInstanceWmi_f((IntPtr) pInst, lFlags, pCtx, ppCallResult, (int) this.scope.Options.Authentication, (int) this.scope.Options.Impersonation, this.pWbemServiecsSecurityHelper, this.scope.Options.Username, this.scope.Options.GetPassword(), this.scope.Options.Authority);
     }
     return num;
 }
示例#47
0
		int System.Management.IWbemServices_Old.CreateInstanceEnumAsync_(string strFilter, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler)
		{
			Type type = null;
			int num;
			try
			{
				EventSource.preventShutdownLock.AcquireReaderLock(-1);
				if (EventSource.shutdownInProgress == 0)
				{
					int tickCount = Environment.TickCount + 100;
					foreach (Type key in this.instrumentedAssembly.mapTypeToConverter.Keys)
					{
						if (string.Compare(ManagedNameAttribute.GetMemberName(key), strFilter, StringComparison.Ordinal) != 0)
						{
							continue;
						}
						type = key;
						break;
					}
					if (null != type)
					{
						int num1 = 64;
						IntPtr[] value = new IntPtr[num1];
						IntPtr[] intPtrArray = new IntPtr[num1];
						ConvertToWMI[] convertToWMIArray = new ConvertToWMI[num1];
						IWbemClassObjectFreeThreaded[] wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded[num1];
						int num2 = 0;
						int V_8 = 0;
						object processIdentity = Instrumentation.ProcessIdentity;
						try
						{
							InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
							foreach (DictionaryEntry dictionaryEntry in InstrumentedAssembly.mapIDToPublishedObject)
							{
								if (EventSource.shutdownInProgress == 0)
								{
									if (type != dictionaryEntry.Value.GetType())
									{
										continue;
									}
									if (convertToWMIArray[num2] != null)
									{
										lock (dictionaryEntry.Value)
										{
											convertToWMIArray[num2](dictionaryEntry.Value);
										}
										value[num2] = (IntPtr)convertToWMIArray[num2].Target.GetType().GetField("instWbemObjectAccessIP").GetValue(convertToWMIArray[num2].Target);
										Marshal.AddRef(value[num2]);
										wbemClassObjectFreeThreaded[num2] = new IWbemClassObjectFreeThreaded(value[num2]);
										wbemClassObjectFreeThreaded[num2].Put_("ProcessId", 0, ref processIdentity, 0);
										if (num2 == 0)
										{
											int V_15;
											WmiNetUtilsHelper.GetPropertyHandle_f27(27, wbemClassObjectFreeThreaded[num2], "InstanceId", out V_15, out V_8);
										}
									}
									else
									{
										object obj = Activator.CreateInstance((Type)this.instrumentedAssembly.mapTypeToConverter[type]);
										convertToWMIArray[num2] = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), obj, "ToWMI");
										lock (dictionaryEntry.Value)
										{
											convertToWMIArray[num2](dictionaryEntry.Value);
										}
										value[num2] = (IntPtr)obj.GetType().GetField("instWbemObjectAccessIP").GetValue(obj);
										Marshal.AddRef(value[num2]);
										wbemClassObjectFreeThreaded[num2] = new IWbemClassObjectFreeThreaded(value[num2]);
										wbemClassObjectFreeThreaded[num2].Put_("ProcessId", 0, ref processIdentity, 0);
										if (num2 == 0)
										{
											int V_13;
											WmiNetUtilsHelper.GetPropertyHandle_f27(27, wbemClassObjectFreeThreaded[num2], "InstanceId", out V_13, out V_8);
										}
									}
									string str = (string)dictionaryEntry.Key;
									WmiNetUtilsHelper.WritePropertyValue_f28(28, wbemClassObjectFreeThreaded[num2], V_8, (str.Length + 1) * 2, str);
									num2++;
									if (num2 != num1 && Environment.TickCount < tickCount)
									{
										continue;
									}
									for (int i = 0; i < num2; i++)
									{
										WmiNetUtilsHelper.Clone_f(12, value[i], out intPtrArray[i]);
									}
									int num3 = pResponseHandler.Indicate_(num2, intPtrArray);
									for (int j = 0; j < num2; j++)
									{
										Marshal.Release(intPtrArray[j]);
									}
									if (num3 == 0)
									{
										num2 = 0;
										tickCount = Environment.TickCount + 100;
									}
									else
									{
										num = 0;
										return num;
									}
								}
								else
								{
									num = 0;
									return num;
								}
							}
						}
						finally
						{
							InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
						}
						if (num2 > 0)
						{
							for (int k = 0; k < num2; k++)
							{
								WmiNetUtilsHelper.Clone_f(12, value[k], out intPtrArray[k]);
							}
							pResponseHandler.Indicate_(num2, intPtrArray);
							for (int l = 0; l < num2; l++)
							{
								Marshal.Release(intPtrArray[l]);
							}
						}
						return 0;
					}
					else
					{
						num = 0;
					}
				}
				else
				{
					num = 0;
				}
			}
			finally
			{
				pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
				Marshal.ReleaseComObject(pResponseHandler);
				EventSource.preventShutdownLock.ReleaseReaderLock();
			}
			return num;
		}
示例#48
0
 public int CompareTo_(Int32 lFlags, IWbemClassObjectFreeThreaded pCompareTo)
 {
     if(pWbemClassObject == IntPtr.Zero)
         throw new ObjectDisposedException(name);
     int res = WmiNetUtilsHelper.CompareTo_f(16, pWbemClassObject, lFlags, pCompareTo.pWbemClassObject);
     GC.KeepAlive ( this ) ;
     return res ;
 }
示例#49
0
        public int SpawnInstance_(Int32 lFlags, out IWbemClassObjectFreeThreaded ppNewInstance)
        {
            if(pWbemClassObject == IntPtr.Zero)
                throw new ObjectDisposedException(name);
            IntPtr pWbemClassObjectNew;
            int hResult = WmiNetUtilsHelper.SpawnInstance_f(15, pWbemClassObject, lFlags, out pWbemClassObjectNew);
            if(hResult < 0)
                ppNewInstance = null;
            else
                ppNewInstance = new IWbemClassObjectFreeThreaded(pWbemClassObjectNew);

            GC.KeepAlive ( this ) ;
            return hResult;
        }
示例#50
0
        public int Clone_(out IWbemClassObjectFreeThreaded ppCopy)
        {
            if(pWbemClassObject == IntPtr.Zero)
                throw new ObjectDisposedException(name);
            IntPtr pWbemClassObjectNew;
            int hResult = WmiNetUtilsHelper.Clone_f(12, pWbemClassObject, out pWbemClassObjectNew);
            if(hResult < 0)
                ppCopy = null;
            else
                ppCopy = new IWbemClassObjectFreeThreaded(pWbemClassObjectNew);

            GC.KeepAlive ( this ) ;
            return hResult;
        }
 internal int ExecMethodAsync_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObjectFreeThreaded pInParams, IWbemObjectSink pResponseHandler)
 {
     return this.pWbemServiecsSecurityHelper.ExecMethodAsync_(strObjectPath, strMethodName, lFlags, pCtx, (IntPtr) pInParams, pResponseHandler);
 }
 internal static string GetManagementPath(IWbemClassObjectFreeThreaded wbemObject)
 {
     string str = null;
     int errorCode = -2147217407;
     if (wbemObject == null)
     {
         return str;
     }
     int pType = 0;
     int plFlavor = 0;
     object pVal = null;
     if ((wbemObject.Get_("__PATH", 0, ref pVal, ref pType, ref plFlavor) < 0) || (pVal == DBNull.Value))
     {
         errorCode = wbemObject.Get_("__RELPATH", 0, ref pVal, ref pType, ref plFlavor);
         if (errorCode < 0)
         {
             if ((errorCode & 0xfffff000L) == 0x80041000L)
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             }
             else
             {
                 Marshal.ThrowExceptionForHR(errorCode);
             }
         }
     }
     if (DBNull.Value == pVal)
     {
         return null;
     }
     return (string) pVal;
 }
 internal int PutInstanceAsync_(IWbemClassObjectFreeThreaded pInst, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler)
 {
     return this.pWbemServiecsSecurityHelper.PutInstanceAsync_((IntPtr) pInst, lFlags, pCtx, pResponseHandler);
 }
示例#54
0
 public int PutMethod_(string wszName, Int32 lFlags, IWbemClassObjectFreeThreaded pInSignature, IWbemClassObjectFreeThreaded pOutSignature)
 {
     if(pWbemClassObject == IntPtr.Zero)
         throw new ObjectDisposedException(name);
     int res = WmiNetUtilsHelper.PutMethod_f(20, pWbemClassObject, wszName, lFlags, pInSignature, pOutSignature);
     GC.KeepAlive ( this ) ;
     return res ;
 }
		public int SpawnInstance_(int lFlags, out IWbemClassObjectFreeThreaded ppNewInstance)
		{
			IntPtr intPtr;
			if (this.pWbemClassObject != IntPtr.Zero)
			{
				int num = WmiNetUtilsHelper.SpawnInstance_f(15, this.pWbemClassObject, lFlags, out intPtr);
				if (num >= 0)
				{
					ppNewInstance = new IWbemClassObjectFreeThreaded(intPtr);
				}
				else
				{
					ppNewInstance = null;
				}
				GC.KeepAlive(this);
				return num;
			}
			else
			{
				throw new ObjectDisposedException(IWbemClassObjectFreeThreaded.name);
			}
		}
示例#56
0
        public int NextMethod_(Int32 lFlags, out string pstrName, out IWbemClassObjectFreeThreaded ppInSignature, out IWbemClassObjectFreeThreaded ppOutSignature)
        {
            if(pWbemClassObject == IntPtr.Zero)
                throw new ObjectDisposedException(name);

            // 
            IntPtr pInSignature;
            IntPtr pOutSignature;
            int hResult = WmiNetUtilsHelper.NextMethod_f(23, pWbemClassObject, lFlags, out pstrName, out pInSignature, out pOutSignature);
            ppInSignature = null;
            ppOutSignature = null;
            if(hResult >= 0)
            {
                // This can be NULL
                if(pInSignature != IntPtr.Zero)
                    ppInSignature = new IWbemClassObjectFreeThreaded(pInSignature);
                if(pOutSignature != IntPtr.Zero)
                    ppOutSignature = new IWbemClassObjectFreeThreaded(pOutSignature);
            }
            GC.KeepAlive ( this ) ;
            return hResult;
        }
		public int PutMethod_(string wszName, int lFlags, IWbemClassObjectFreeThreaded pInSignature, IWbemClassObjectFreeThreaded pOutSignature)
		{
			if (this.pWbemClassObject != IntPtr.Zero)
			{
				int num = WmiNetUtilsHelper.PutMethod_f(20, this.pWbemClassObject, wszName, lFlags, pInSignature, pOutSignature);
				GC.KeepAlive(this);
				return num;
			}
			else
			{
				throw new ObjectDisposedException(IWbemClassObjectFreeThreaded.name);
			}
		}
示例#58
0
		public int GetObject_ (string strObjectPath, int lFlags, IWbemContext pCtx, out IWbemClassObjectFreeThreaded ppObject, IntPtr ppCallResult)
		{
			if (ppCallResult == IntPtr.Zero) {
				//Get Class from Path


				//Get IntPtr for Class
				ppCallResult = System.Runtime.InteropServices.Marshal.GetIUnknownForObject (this);
			}
			ppObject = new IWbemClassObjectFreeThreaded(ppCallResult);
			return 0;
		}
示例#59
0
		int System.Management.IWbemServices_Old.GetObjectAsync_(string strObjectPath, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler)
		{
			Match match = Regex.Match(strObjectPath.ToLower(CultureInfo.InvariantCulture), "(.*?)\\.instanceid=\"(.*?)\",processid=\"(.*?)\"");
			if (match.Success)
			{
				//match.Groups[1].Value;
				string value = match.Groups[2].Value;
				string str = match.Groups[3].Value;
				if (Instrumentation.ProcessIdentity == str)
				{
					int num = ((IConvertible)value).ToInt32((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)));
					object item = null;
					try
					{
						InstrumentedAssembly.readerWriterLock.AcquireReaderLock(-1);
						item = InstrumentedAssembly.mapIDToPublishedObject[num.ToString((IFormatProvider)CultureInfo.InvariantCulture.GetFormat(typeof(int)))];
					}
					finally
					{
						InstrumentedAssembly.readerWriterLock.ReleaseReaderLock();
					}
					if (item != null)
					{
						Type type = (Type)this.instrumentedAssembly.mapTypeToConverter[item.GetType()];
						if (type != null)
						{
							object obj = Activator.CreateInstance(type);
							ConvertToWMI convertToWMI = (ConvertToWMI)Delegate.CreateDelegate(typeof(ConvertToWMI), obj, "ToWMI");
							lock (item)
							{
								convertToWMI(item);
							}
							IntPtr[] intPtrArray = new IntPtr[1];
							intPtrArray[0] = (IntPtr)obj.GetType().GetField("instWbemObjectAccessIP").GetValue(obj);
							IntPtr[] intPtrArray1 = intPtrArray;
							Marshal.AddRef(intPtrArray1[0]);
							IWbemClassObjectFreeThreaded wbemClassObjectFreeThreaded = new IWbemClassObjectFreeThreaded(intPtrArray1[0]);
							object processIdentity = num;
							wbemClassObjectFreeThreaded.Put_("InstanceId", 0, ref processIdentity, 0);
							processIdentity = Instrumentation.ProcessIdentity;
							wbemClassObjectFreeThreaded.Put_("ProcessId", 0, ref processIdentity, 0);
							pResponseHandler.Indicate_(1, intPtrArray1);
							pResponseHandler.SetStatus_(0, 0, null, IntPtr.Zero);
							Marshal.ReleaseComObject(pResponseHandler);
							return 0;
						}
					}
					pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
					Marshal.ReleaseComObject(pResponseHandler);
					return -2147217406;
				}
				else
				{
					pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
					Marshal.ReleaseComObject(pResponseHandler);
					return -2147217406;
				}
			}
			else
			{
				pResponseHandler.SetStatus_(0, -2147217406, null, IntPtr.Zero);
				Marshal.ReleaseComObject(pResponseHandler);
				return -2147217406;
			}
		}
 internal int GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, ref IWbemClassObjectFreeThreaded ppObject, IntPtr ppCallResult)
 {
     int num = -2147217407;
     if (!object.ReferenceEquals(ppCallResult, IntPtr.Zero))
     {
         num = this.pWbemServiecsSecurityHelper.GetObject_(strObjectPath, lFlags, pCtx, out ppObject, ppCallResult);
     }
     return num;
 }