예제 #1
0
 int IWbemServices_Old.PutInstance_([In][MarshalAs(UnmanagedType.Interface)]  IWbemClassObject_DoNotMarshal pInst,
                                    [In] Int32 lFlags,
                                    [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                    [In] IntPtr ppCallResult)
 {
     return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED));
 }
예제 #2
0
 int IWbemServices_Old.PutInstanceAsync_([In][MarshalAs(UnmanagedType.Interface)]  IWbemClassObject_DoNotMarshal pInst,
                                         [In] Int32 lFlags,
                                         [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                         [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
 {
     return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED));
 }
예제 #3
0
        public ManagementBaseObject WaitForNextEvent()
        {
            ManagementBaseObject obj2 = null;

            this.Initialize();
            lock (this)
            {
                SecurityHandler securityHandler = this.Scope.GetSecurityHandler();
                int             errorCode       = 0;
                try
                {
                    if (this.enumWbem == null)
                    {
                        errorCode = this.scope.GetSecuredIWbemServicesHandler(this.Scope.GetIWbemServices()).ExecNotificationQuery_(this.query.QueryLanguage, this.query.QueryString, this.options.Flags, this.options.GetContext(), ref this.enumWbem);
                    }
                    if (errorCode >= 0)
                    {
                        if ((this.cachedCount - this.cacheIndex) == 0)
                        {
                            IWbemClassObject_DoNotMarshal[] ppOutParams = new IWbemClassObject_DoNotMarshal[this.options.BlockSize];
                            int lTimeout = (ManagementOptions.InfiniteTimeout == this.options.Timeout) ? -1 : ((int)this.options.Timeout.TotalMilliseconds);
                            errorCode       = this.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(lTimeout, (uint)this.options.BlockSize, ppOutParams, ref this.cachedCount);
                            this.cacheIndex = 0;
                            if (errorCode >= 0)
                            {
                                if (this.cachedCount == 0)
                                {
                                    ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);
                                }
                                for (int i = 0; i < this.cachedCount; i++)
                                {
                                    this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(ppOutParams[i]));
                                }
                            }
                        }
                        if (errorCode >= 0)
                        {
                            obj2 = new ManagementBaseObject(this.cachedObjects[this.cacheIndex]);
                            this.cacheIndex++;
                        }
                    }
                }
                finally
                {
                    securityHandler.Reset();
                }
                if (errorCode >= 0)
                {
                    return(obj2);
                }
                if ((errorCode & 0xfffff000L) == 0x80041000L)
                {
                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
                    return(obj2);
                }
                Marshal.ThrowExceptionForHR(errorCode);
            }
            return(obj2);
        }
예제 #4
0
 int IWbemServices_Old.GetObject_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                  [In] Int32 lFlags,
                                  [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                  [In][Out][MarshalAs(UnmanagedType.Interface)]  ref IWbemClassObject_DoNotMarshal ppObject,
                                  [In] IntPtr ppCallResult)
 {
     return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED));
 }
예제 #5
0
 int IWbemServices_Old.ExecMethodAsync_([In][MarshalAs(UnmanagedType.BStr)]  string strObjectPath,
                                        [In][MarshalAs(UnmanagedType.BStr)]  string strMethodName,
                                        [In] Int32 lFlags,
                                        [In][MarshalAs(UnmanagedType.Interface)]  IWbemContext pCtx,
                                        [In][MarshalAs(UnmanagedType.Interface)]  IWbemClassObject_DoNotMarshal pInParams,
                                        [In][MarshalAs(UnmanagedType.Interface)]  IWbemObjectSink pResponseHandler)
 {
     return((int)(tag_WBEMSTATUS.WBEM_E_NOT_SUPPORTED));
 }
예제 #6
0
        internal static int Clone(int vFunc, IntPtr pWbemClassObject, out IntPtr ppCopy)
        {
            UnixWbemClassObject           obj    = UnixWbemClassObject.ToManaged(pWbemClassObject);
            IWbemClassObject_DoNotMarshal result = null;
            int ret = obj.Clone_(out result);

            ppCopy = UnixWbemClassObject.ToPointer(result);
            return(ret);
        }
예제 #7
0
        internal static int GetMethod(int vFunc, IntPtr pWbemClassObject, string wszName, int lFlags, out IntPtr ppInSignature, out IntPtr ppOutSignature)
        {
            UnixWbemClassObject           obj     = UnixWbemClassObject.ToManaged(pWbemClassObject);
            IWbemClassObject_DoNotMarshal inSign  = null;
            IWbemClassObject_DoNotMarshal outSign = null;
            int ret = obj.GetMethod_(wszName, lFlags, out inSign, out outSign);

            ppInSignature  = UnixWbemClassObject.ToPointer(inSign);
            ppOutSignature = UnixWbemClassObject.ToPointer(outSign);
            return(ret);
        }
예제 #8
0
		public int Next_ (int lTimeout, int uCount, IWbemClassObject_DoNotMarshal[] apObjects, out uint puReturned)
		{
			uint ret = 0;
			while(_enumerator.MoveNext())
			{
				apObjects[ret] = _enumerator.Current;
				ret++;
				if (ret >= uCount) break;
			}
			puReturned = ret;
			return ret > 0 ? 0 : 1;
		}
예제 #9
0
 public bool MoveNext()
 {
     if (this.isDisposed)
     {
         throw new ObjectDisposedException(name);
     }
     if (this.atEndOfCollection)
     {
         return(false);
     }
     this.cacheIndex++;
     if ((this.cachedCount - this.cacheIndex) == 0L)
     {
         int             lTimeout                    = (this.collectionObject.options.Timeout.Ticks == 0x7fffffffffffffffL) ? -1 : ((int)this.collectionObject.options.Timeout.TotalMilliseconds);
         SecurityHandler securityHandler             = this.collectionObject.scope.GetSecurityHandler();
         IWbemClassObject_DoNotMarshal[] ppOutParams = new IWbemClassObject_DoNotMarshal[this.collectionObject.options.BlockSize];
         int errorCode = this.collectionObject.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(lTimeout, (uint)this.collectionObject.options.BlockSize, ppOutParams, ref this.cachedCount);
         securityHandler.Reset();
         if (errorCode >= 0)
         {
             for (int i = 0; i < this.cachedCount; i++)
             {
                 this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(ppOutParams[i]));
             }
         }
         if (errorCode < 0)
         {
             if ((errorCode & 0xfffff000L) == 0x80041000L)
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
             }
             else
             {
                 Marshal.ThrowExceptionForHR(errorCode);
             }
         }
         else
         {
             if ((errorCode == 0x40004) && (this.cachedCount == 0))
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus)errorCode);
             }
             if ((errorCode == 1) && (this.cachedCount == 0))
             {
                 this.atEndOfCollection = true;
                 this.cacheIndex--;
                 return(false);
             }
         }
         this.cacheIndex = 0;
     }
     return(true);
 }
예제 #10
0
        public virtual int GetMethod_(string wszName, int lFlags, out IWbemClassObject_DoNotMarshal ppInSignature, out IWbemClassObject_DoNotMarshal ppOutSignature)
        {
            var method = _handler.Methods.FirstOrDefault(x => x.Name.Equals(wszName, StringComparison.OrdinalIgnoreCase));

            ppInSignature  = null;
            ppOutSignature = null;
            if (string.IsNullOrEmpty(method.Name))
            {
                return(0x40005);
            }
            UnixWbemMethodCreator.CreateSignature(method, out ppInSignature, out ppOutSignature);
            return(0);
        }
예제 #11
0
        /// <summary>
        /// Creates the signature.
        /// </summary>
        /// <param name='info'>
        /// Info.
        /// </param>
        /// <param name='ppInSignature'>
        /// Pp in signature.
        /// </param>
        /// <param name='ppOutSignature'>
        /// Pp out signature.
        /// </param>
        public static void CreateSignature(UnixCimMethodInfo info, out IWbemClassObject_DoNotMarshal ppInSignature, out IWbemClassObject_DoNotMarshal ppOutSignature)
        {
            Type inType  = null;
            Type outType = null;

            if (string.IsNullOrEmpty(info.InSignatureType))
            {
                inType = typeof(UNIX_MethodParameterClass);
            }
            else
            {
                inType = Type.GetType(info.InSignatureType, false, true);
            }

            if (string.IsNullOrEmpty(info.OutSignatureType))
            {
                outType = typeof(UNIX_MethodParameterClass);
            }
            else
            {
                outType = Type.GetType(info.OutSignatureType, false, true);
            }

            var inClass  = (UNIX_MethodParameterClass)WMIDatabaseFactory.GetHandler(inType).Get((object)null);
            var outClass = (UNIX_MethodParameterClass)WMIDatabaseFactory.GetHandler(outType).Get((object)null);

            if (info.InProperties != null)
            {
                foreach (var property in info.InProperties)
                {
                    inClass.RegisterProperty(property);
                }
            }

            outClass.RegisterProperty(new UnixWbemPropertyInfo {
                Name = "ReturnValue", Type = CimType.UInt32, Flavor = 0
            });

            if (info.OutProperties != null)
            {
                foreach (var property in info.OutProperties)
                {
                    outClass.RegisterProperty(property);
                }
            }

            ppInSignature  = new UnixWbemClassObject(inClass);
            ppOutSignature = new UnixWbemClassObject(outClass);
        }
예제 #12
0
            public TypeInfo(EventSource source, SchemaNaming naming, Type t)
            {
                this.toWMI = (ConvertFuncToWMI)InstrumentedAssembly.mapTypeToToWMIFunc[t];
                this.toNET = (ConvertFuncToNET)InstrumentedAssembly.mapTypeToToNETFunc[t];
                this.t     = t;
                isSTA      = Thread.CurrentThread.ApartmentState == ApartmentState.STA;
                ManagementClass eventClass = new ManagementClass(naming.NamespaceName + ":" + ManagedNameAttribute.GetMemberName(t));
                PropertyInfo    prop       = typeof(ManagementBaseObject).GetProperty("WmiObject", BindingFlags.Instance | BindingFlags.NonPublic);

                ManagementObject evt = eventClass.CreateInstance();

                obj         = (IWbemClassObject_DoNotMarshal)prop.GetValue(evt, null);
                this.source = source;


                SetBatchSize(batchSize);

                IWbemClassObject_DoNotMarshal obj2;

                obj.Clone_(out obj2);
                xoa1[0] = (IWbemObjectAccess)obj2;
                oa1test = new ClassObjectArray(xoa1);

                writeDWORD1 = new WriteDWORD(xoa1[0].WriteDWORD_);
                writeQWORD1 = new WriteQWORD(xoa1[0].WriteQWORD_);

#if xxx
                string             code       = CodeSpit.Spit(t, xoa1[0]);
                CSharpCodeProvider provider   = new CSharpCodeProvider();
                ICodeCompiler      compiler   = provider.CreateCompiler();
                CompilerParameters parameters = new CompilerParameters();
                parameters.GenerateInMemory = true;

                parameters.ReferencedAssemblies.Add(t.Assembly.Location);
                parameters.ReferencedAssemblies.Add(typeof(WriteDWORD).Assembly.Location);
                parameters.ReferencedAssemblies.Add(typeof(Event).Assembly.Location);
                CompilerResults results = compiler.CompileAssemblyFromSource(parameters, code);
                foreach (CompilerError err in results.Errors)
                {
                    Console.WriteLine(err.ToString());
                }
                Type dynType = results.CompiledAssembly.GetType("Hack");

                MethodInfo doit = dynType.GetMethod("Func");

                managedToIWbem = (ManagedToIWbem)Delegate.CreateDelegate(typeof(ManagedToIWbem), doit);
#endif
            }
예제 #13
0
        public virtual int NextMethod_(int lFlags, out string pstrName, out IWbemClassObject_DoNotMarshal ppInSignature, out IWbemClassObject_DoNotMarshal ppOutSignature)
        {
            var method = _handler.NextMethod();

            pstrName       = null;
            ppInSignature  = null;
            ppOutSignature = null;
            if (string.IsNullOrEmpty(method.Name))
            {
                return(0x40005);
            }

            pstrName = method.Name;
            UnixWbemMethodCreator.CreateSignature(method, out ppInSignature, out ppOutSignature);

            return(0);
        }
예제 #14
0
        internal static int NextMethod(int vFunc, IntPtr pWbemClassObject, int lFlags, out string pstrName, out IntPtr ppInSignature, out IntPtr ppOutSignature)
        {
            UnixWbemClassObject           obj     = UnixWbemClassObject.ToManaged(pWbemClassObject);
            IWbemClassObject_DoNotMarshal inSign  = null;
            IWbemClassObject_DoNotMarshal outSign = null;
            int ret = obj.NextMethod_(lFlags, out pstrName, out inSign, out outSign);

            if (ret >= 0 && inSign != null && outSign != null)
            {
                ppInSignature  = UnixWbemClassObject.ToPointer(inSign);
                ppOutSignature = UnixWbemClassObject.ToPointer(outSign);
            }
            else
            {
                ppInSignature  = IntPtr.Zero;
                ppOutSignature = IntPtr.Zero;
            }
            return(ret);
        }
예제 #15
0
		/// <summary>
		/// Creates the signature.
		/// </summary>
		/// <param name='info'>
		/// Info.
		/// </param>
		/// <param name='ppInSignature'>
		/// Pp in signature.
		/// </param>
		/// <param name='ppOutSignature'>
		/// Pp out signature.
		/// </param>
		public static void CreateSignature (UnixCimMethodInfo info, out IWbemClassObject_DoNotMarshal ppInSignature, out IWbemClassObject_DoNotMarshal ppOutSignature)
		{
			Type inType = null;
			Type outType = null; 
			if (string.IsNullOrEmpty (info.InSignatureType)) {
				inType = typeof(UNIX_MethodParameterClass);
			} else {
				inType = Type.GetType (info.InSignatureType, false, true);
			}

			if (string.IsNullOrEmpty (info.OutSignatureType)) {
				outType = typeof(UNIX_MethodParameterClass);
			} else {
				outType = Type.GetType (info.OutSignatureType, false, true);
			}

			var inClass = (UNIX_MethodParameterClass)WMIDatabaseFactory.GetHandler (inType).Get ((object)null);
			var outClass = (UNIX_MethodParameterClass)WMIDatabaseFactory.GetHandler (outType).Get ((object)null);
			
			if (info.InProperties != null) {
				foreach (var property in info.InProperties) {
					inClass.RegisterProperty (property);
				}
			}

			outClass.RegisterProperty (new UnixWbemPropertyInfo { Name = "ReturnValue", Type = CimType.UInt32, Flavor = 0  });

			if (info.OutProperties != null) 
			{
				foreach (var property in info.OutProperties) {
					outClass.RegisterProperty (property);
				}
			}

			ppInSignature = new UnixWbemClassObject(inClass);
			ppOutSignature = new UnixWbemClassObject(outClass);
		}
예제 #16
0
 int System.Management.IWbemServices_Old.PutInstanceAsync_(IWbemClassObject_DoNotMarshal pInst, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler)
 {
     return(-2147217396);
 }
예제 #17
0
 int System.Management.IWbemServices_Old.GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, out IWbemClassObject_DoNotMarshal ppObject, IntPtr ppCallResult)
 {
     ppObject = null;
     return(-2147217396);
 }
예제 #18
0
 int System.Management.IWbemServices_Old.ExecMethod_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObject_DoNotMarshal pInParams, out IWbemClassObject_DoNotMarshal ppOutParams, IntPtr ppCallResult)
 {
     ppOutParams = null;
     return(-2147217396);
 }
            //****************************************
            //MoveNext
            //****************************************
            /// <summary>
            ///    Indicates whether the enumerator has moved to
            ///    the next object in the enumeration.
            /// </summary>
            /// <returns>
            /// <para><see langword='true'/>, if the enumerator was
            ///    successfully advanced to the next element; <see langword='false'/> if the enumerator has
            ///    passed the end of the collection.</para>
            /// </returns>
            public bool MoveNext()
            {
                if (isDisposed)
                {
                    throw new ObjectDisposedException(name);
                }

                //If there are no more objects in the collection return false
                if (atEndOfCollection)
                {
                    return(false);
                }

                //Look for the next object
                cacheIndex++;

                if ((cachedCount - cacheIndex) == 0) //cache is empty - need to get more objects
                {
                    //If the timeout is set to infinite, need to use the WMI infinite constant
                    int timeout = (collectionObject.options.Timeout.Ticks == long.MaxValue) ?
                                  (int)tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE : (int)collectionObject.options.Timeout.TotalMilliseconds;

                    //Get the next [BLockSize] objects within the specified timeout
                    SecurityHandler securityHandler = collectionObject.scope.GetSecurityHandler();

                    //Because Interop doesn't support custom marshalling for arrays, we have to use
                    //the "DoNotMarshal" objects in the interop and then convert to the "FreeThreaded"
                    //counterparts afterwards.
                    IWbemClassObject_DoNotMarshal[] tempArray = new IWbemClassObject_DoNotMarshal[collectionObject.options.BlockSize];

                    int status = collectionObject.scope.GetSecuredIEnumWbemClassObjectHandler(enumWbem).Next_(timeout, (uint)collectionObject.options.BlockSize, tempArray, ref cachedCount);

                    securityHandler.Reset();

                    if (status >= 0)
                    {
                        //Convert results and put them in cache.

                        for (int i = 0; i < cachedCount; i++)
                        {
                            cachedObjects[i] = new IWbemClassObjectFreeThreaded
                                               (
                                Marshal.GetIUnknownForObject(tempArray[i])
                                               );
                        }
                    }

                    if (status < 0)
                    {
                        if ((status & 0xfffff000) == 0x80041000)
                        {
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                        }
                        else
                        {
                            Marshal.ThrowExceptionForHR(status, WmiNetUtilsHelper.GetErrorInfo_f());
                        }
                    }
                    else
                    {
                        //If there was a timeout and no object can be returned we throw a timeout exception...
                        if ((status == (int)tag_WBEMSTATUS.WBEM_S_TIMEDOUT) && (cachedCount == 0))
                        {
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                        }

                        //If not timeout and no objects were returned - we're at the end of the collection
                        if ((status == (int)tag_WBEMSTATUS.WBEM_S_FALSE) && (cachedCount == 0))
                        {
                            atEndOfCollection = true;
                            cacheIndex--; //back to last object

                            /* This call to Dispose is being removed as per discussion with URT people and the newly supported
                             * Dispose() call in the foreach implementation itself.
                             *
                             *                              //Release the COM object (so that the user doesn't have to)
                             *                              Dispose();
                             */
                            return(false);
                        }
                    }

                    cacheIndex = 0;
                }

                return(true);
            }
 public bool MoveNext()
 {
     if (this.isDisposed)
     {
         throw new ObjectDisposedException(name);
     }
     if (this.atEndOfCollection)
     {
         return false;
     }
     this.cacheIndex++;
     if ((this.cachedCount - this.cacheIndex) == 0L)
     {
         int lTimeout = (this.collectionObject.options.Timeout.Ticks == 0x7fffffffffffffffL) ? -1 : ((int) this.collectionObject.options.Timeout.TotalMilliseconds);
         SecurityHandler securityHandler = this.collectionObject.scope.GetSecurityHandler();
         IWbemClassObject_DoNotMarshal[] ppOutParams = new IWbemClassObject_DoNotMarshal[this.collectionObject.options.BlockSize];
         int errorCode = this.collectionObject.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(lTimeout, (uint) this.collectionObject.options.BlockSize, ppOutParams, ref this.cachedCount);
         securityHandler.Reset();
         if (errorCode >= 0)
         {
             for (int i = 0; i < this.cachedCount; i++)
             {
                 this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(ppOutParams[i]));
             }
         }
         if (errorCode < 0)
         {
             if ((errorCode & 0xfffff000L) == 0x80041000L)
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             }
             else
             {
                 Marshal.ThrowExceptionForHR(errorCode);
             }
         }
         else
         {
             if ((errorCode == 0x40004) && (this.cachedCount == 0))
             {
                 ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             }
             if ((errorCode == 1) && (this.cachedCount == 0))
             {
                 this.atEndOfCollection = true;
                 this.cacheIndex--;
                 return false;
             }
         }
         this.cacheIndex = 0;
     }
     return true;
 }
 public ManagementBaseObject WaitForNextEvent()
 {
     ManagementBaseObject obj2 = null;
     this.Initialize();
     lock (this)
     {
         SecurityHandler securityHandler = this.Scope.GetSecurityHandler();
         int errorCode = 0;
         try
         {
             if (this.enumWbem == null)
             {
                 errorCode = this.scope.GetSecuredIWbemServicesHandler(this.Scope.GetIWbemServices()).ExecNotificationQuery_(this.query.QueryLanguage, this.query.QueryString, this.options.Flags, this.options.GetContext(), ref this.enumWbem);
             }
             if (errorCode >= 0)
             {
                 if ((this.cachedCount - this.cacheIndex) == 0)
                 {
                     IWbemClassObject_DoNotMarshal[] ppOutParams = new IWbemClassObject_DoNotMarshal[this.options.BlockSize];
                     int lTimeout = (ManagementOptions.InfiniteTimeout == this.options.Timeout) ? -1 : ((int) this.options.Timeout.TotalMilliseconds);
                     errorCode = this.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(lTimeout, (uint) this.options.BlockSize, ppOutParams, ref this.cachedCount);
                     this.cacheIndex = 0;
                     if (errorCode >= 0)
                     {
                         if (this.cachedCount == 0)
                         {
                             ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);
                         }
                         for (int i = 0; i < this.cachedCount; i++)
                         {
                             this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(ppOutParams[i]));
                         }
                     }
                 }
                 if (errorCode >= 0)
                 {
                     obj2 = new ManagementBaseObject(this.cachedObjects[this.cacheIndex]);
                     this.cacheIndex++;
                 }
             }
         }
         finally
         {
             securityHandler.Reset();
         }
         if (errorCode >= 0)
         {
             return obj2;
         }
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             return obj2;
         }
         Marshal.ThrowExceptionForHR(errorCode);
     }
     return obj2;
 }
예제 #22
0
		public virtual int PutMethod_ (string wszName, int lFlags, IWbemClassObject_DoNotMarshal pInSignature, IWbemClassObject_DoNotMarshal pOutSignature)
		{
			pInSignature = null;
			pOutSignature = null;
			return 0;
		}
예제 #23
0
		public virtual int NextMethod_ (int lFlags, out string pstrName, out IWbemClassObject_DoNotMarshal ppInSignature, out IWbemClassObject_DoNotMarshal ppOutSignature)
		{
			var method = _handler.NextMethod ();
			pstrName = null;
			ppInSignature = null;
			ppOutSignature = null;
			if (string.IsNullOrEmpty (method.Name)) {
				return 0x40005;
			}
			
			pstrName = method.Name;
			UnixWbemMethodCreator.CreateSignature (method, out ppInSignature, out ppOutSignature);

			return 0;
		}
예제 #24
0
		public virtual int GetMethod_ (string wszName, int lFlags, out IWbemClassObject_DoNotMarshal ppInSignature, out IWbemClassObject_DoNotMarshal ppOutSignature)
		{
			var method = _handler.Methods.FirstOrDefault (x => x.Name.Equals (wszName, StringComparison.OrdinalIgnoreCase));
			ppInSignature = null;
			ppOutSignature = null;
			if (string.IsNullOrEmpty (method.Name)) {
				return 0x40005;
			}
			UnixWbemMethodCreator.CreateSignature (method, out ppInSignature, out ppOutSignature);
			return 0;
		}
 internal static object MapValueToWmiValue(object val, out bool isArray, out CimType type)
 {
     object objectForIUnknown = DBNull.Value;
     CultureInfo invariantCulture = CultureInfo.InvariantCulture;
     isArray = false;
     type = CimType.None;
     if (val != null)
     {
         isArray = val.GetType().IsArray;
         System.Type type2 = val.GetType();
         if (isArray)
         {
             System.Type elementType = type2.GetElementType();
             if (elementType.IsPrimitive)
             {
                 if (elementType == typeof(byte))
                 {
                     byte[] buffer = (byte[]) val;
                     int length = buffer.Length;
                     type = CimType.UInt8;
                     objectForIUnknown = new short[length];
                     for (int i = 0; i < length; i++)
                     {
                         ((short[]) objectForIUnknown)[i] = ((IConvertible) buffer[i]).ToInt16(null);
                     }
                     return objectForIUnknown;
                 }
                 if (elementType == typeof(sbyte))
                 {
                     sbyte[] numArray = (sbyte[]) val;
                     int num3 = numArray.Length;
                     type = CimType.SInt8;
                     objectForIUnknown = new short[num3];
                     for (int j = 0; j < num3; j++)
                     {
                         ((short[]) objectForIUnknown)[j] = ((IConvertible) numArray[j]).ToInt16(null);
                     }
                     return objectForIUnknown;
                 }
                 if (elementType == typeof(bool))
                 {
                     type = CimType.Boolean;
                     return (bool[]) val;
                 }
                 if (elementType == typeof(ushort))
                 {
                     ushort[] numArray2 = (ushort[]) val;
                     int num5 = numArray2.Length;
                     type = CimType.UInt16;
                     objectForIUnknown = new int[num5];
                     for (int k = 0; k < num5; k++)
                     {
                         ((int[]) objectForIUnknown)[k] = ((IConvertible) numArray2[k]).ToInt32(null);
                     }
                     return objectForIUnknown;
                 }
                 if (elementType == typeof(short))
                 {
                     type = CimType.SInt16;
                     return (short[]) val;
                 }
                 if (elementType == typeof(int))
                 {
                     type = CimType.SInt32;
                     return (int[]) val;
                 }
                 if (elementType == typeof(uint))
                 {
                     uint[] numArray3 = (uint[]) val;
                     int num7 = numArray3.Length;
                     type = CimType.UInt32;
                     objectForIUnknown = new string[num7];
                     for (int m = 0; m < num7; m++)
                     {
                         ((string[]) objectForIUnknown)[m] = numArray3[m].ToString((IFormatProvider) invariantCulture.GetFormat(typeof(uint)));
                     }
                     return objectForIUnknown;
                 }
                 if (elementType == typeof(ulong))
                 {
                     ulong[] numArray4 = (ulong[]) val;
                     int num9 = numArray4.Length;
                     type = CimType.UInt64;
                     objectForIUnknown = new string[num9];
                     for (int n = 0; n < num9; n++)
                     {
                         ((string[]) objectForIUnknown)[n] = numArray4[n].ToString((IFormatProvider) invariantCulture.GetFormat(typeof(ulong)));
                     }
                     return objectForIUnknown;
                 }
                 if (elementType == typeof(long))
                 {
                     long[] numArray5 = (long[]) val;
                     int num11 = numArray5.Length;
                     type = CimType.SInt64;
                     objectForIUnknown = new string[num11];
                     for (int num12 = 0; num12 < num11; num12++)
                     {
                         ((string[]) objectForIUnknown)[num12] = numArray5[num12].ToString((IFormatProvider) invariantCulture.GetFormat(typeof(long)));
                     }
                     return objectForIUnknown;
                 }
                 if (elementType == typeof(float))
                 {
                     type = CimType.Real32;
                     return (float[]) val;
                 }
                 if (elementType == typeof(double))
                 {
                     type = CimType.Real64;
                     return (double[]) val;
                 }
                 if (elementType == typeof(char))
                 {
                     char[] chArray = (char[]) val;
                     int num13 = chArray.Length;
                     type = CimType.Char16;
                     objectForIUnknown = new short[num13];
                     for (int num14 = 0; num14 < num13; num14++)
                     {
                         ((short[]) objectForIUnknown)[num14] = ((IConvertible) chArray[num14]).ToInt16(null);
                     }
                 }
                 return objectForIUnknown;
             }
             if (elementType == typeof(string))
             {
                 type = CimType.String;
                 return (string[]) val;
             }
             if (val is ManagementBaseObject[])
             {
                 Array array = (Array) val;
                 int num15 = array.Length;
                 type = CimType.Object;
                 objectForIUnknown = new IWbemClassObject_DoNotMarshal[num15];
                 for (int num16 = 0; num16 < num15; num16++)
                 {
                     ((IWbemClassObject_DoNotMarshal[]) objectForIUnknown)[num16] = (IWbemClassObject_DoNotMarshal) Marshal.GetObjectForIUnknown((IntPtr) ((ManagementBaseObject) array.GetValue(num16)).wbemObject);
                 }
             }
             return objectForIUnknown;
         }
         if (type2 == typeof(ushort))
         {
             type = CimType.UInt16;
             return ((IConvertible) ((ushort) val)).ToInt32(null);
         }
         if (type2 == typeof(uint))
         {
             type = CimType.UInt32;
             if ((((uint) val) & 0x80000000) != 0)
             {
                 return Convert.ToString(val, (IFormatProvider) invariantCulture.GetFormat(typeof(uint)));
             }
             return Convert.ToInt32(val, (IFormatProvider) invariantCulture.GetFormat(typeof(int)));
         }
         if (type2 == typeof(ulong))
         {
             type = CimType.UInt64;
             ulong num17 = (ulong) val;
             return num17.ToString((IFormatProvider) invariantCulture.GetFormat(typeof(ulong)));
         }
         if (type2 == typeof(sbyte))
         {
             type = CimType.SInt8;
             return ((IConvertible) ((sbyte) val)).ToInt16(null);
         }
         if (type2 == typeof(byte))
         {
             type = CimType.UInt8;
             return val;
         }
         if (type2 == typeof(short))
         {
             type = CimType.SInt16;
             return val;
         }
         if (type2 == typeof(int))
         {
             type = CimType.SInt32;
             return val;
         }
         if (type2 == typeof(long))
         {
             type = CimType.SInt64;
             return val.ToString();
         }
         if (type2 == typeof(bool))
         {
             type = CimType.Boolean;
             return val;
         }
         if (type2 == typeof(float))
         {
             type = CimType.Real32;
             return val;
         }
         if (type2 == typeof(double))
         {
             type = CimType.Real64;
             return val;
         }
         if (type2 == typeof(char))
         {
             type = CimType.Char16;
             return ((IConvertible) ((char) val)).ToInt16(null);
         }
         if (type2 == typeof(string))
         {
             type = CimType.String;
             return val;
         }
         if (val is ManagementBaseObject)
         {
             type = CimType.Object;
             objectForIUnknown = Marshal.GetObjectForIUnknown((IntPtr) ((ManagementBaseObject) val).wbemObject);
         }
     }
     return objectForIUnknown;
 }
예제 #26
0
			public bool MoveNext()
			{
				int totalMilliseconds;
				if (!this.isDisposed)
				{
					if (!this.atEndOfCollection)
					{
						ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator = this;
						managementObjectEnumerator.cacheIndex = managementObjectEnumerator.cacheIndex + 1;
						if ((long)this.cachedCount - (long)this.cacheIndex == (long)0)
						{
							TimeSpan timeout = this.collectionObject.options.Timeout;
							if (timeout.Ticks == 0x7fffffffffffffffL)
							{
								totalMilliseconds = -1;
							}
							else
							{
								TimeSpan timeSpan = this.collectionObject.options.Timeout;
								totalMilliseconds = (int)timeSpan.TotalMilliseconds;
							}
							int num = totalMilliseconds;
							SecurityHandler securityHandler = this.collectionObject.scope.GetSecurityHandler();
							IWbemClassObject_DoNotMarshal[] wbemClassObjectDoNotMarshalArray = new IWbemClassObject_DoNotMarshal[this.collectionObject.options.BlockSize];
							int num1 = this.collectionObject.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(num, this.collectionObject.options.BlockSize, wbemClassObjectDoNotMarshalArray, ref this.cachedCount);
							securityHandler.Reset();
							if (num1 >= 0)
							{
								for (int i = 0; (long)i < (long)this.cachedCount; i++)
								{
									IntPtr ptr = Marshal.GetIUnknownForObject(wbemClassObjectDoNotMarshalArray[i].NativeObject);
									this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(ptr);
								}
							}
							if (num1 >= 0)
							{
								if (num1 == 0x40004 && this.cachedCount == 0)
								{
									ManagementException.ThrowWithExtendedInfo((ManagementStatus)num1);
								}
								if (num1 == 1 && this.cachedCount == 0)
								{
									this.atEndOfCollection = true;
									ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator1 = this;
									managementObjectEnumerator1.cacheIndex = managementObjectEnumerator1.cacheIndex - 1;
									return false;
								}
							}
							else
							{
								if (((long)num1 & (long)-4096) != (long)-2147217408)
								{
									Marshal.ThrowExceptionForHR(num1);
								}
								else
								{
									ManagementException.ThrowWithExtendedInfo((ManagementStatus)num1);
								}
							}
							this.cacheIndex = 0;
						}
						return true;
					}
					else
					{
						return false;
					}
				}
				else
				{
					throw new ObjectDisposedException(ManagementObjectCollection.ManagementObjectEnumerator.name);
				}
			}
        /// <summary>
        ///    <para>Waits for the next event that matches the specified query to arrive, and
        ///       then returns it.</para>
        /// </summary>
        /// <returns>
        /// <para>A <see cref='System.Management.ManagementBaseObject'/> representing the 
        ///    newly arrived event.</para>
        /// </returns>
        /// <remarks>
        ///    <para>If the event watcher object contains options with
        ///       a specified timeout, the API will wait for the next event only for the specified
        ///       amount of time; otherwise, the API will be blocked until the next event occurs.</para>
        /// </remarks>
        public ManagementBaseObject WaitForNextEvent()
        {
            ManagementBaseObject obj = null;

            Initialize ();
            
            lock(this)
            {
                SecurityHandler securityHandler = Scope.GetSecurityHandler();

                int status = (int)ManagementStatus.NoError;

                try 
                {
                    if (null == enumWbem)   //don't have an enumerator yet - get it
                    {
                        //Execute the query 
                        status = scope.GetSecuredIWbemServicesHandler( Scope.GetIWbemServices() ).ExecNotificationQuery_(
                            query.QueryLanguage,
                            query.QueryString, 
                            options.Flags,
                            options.GetContext (),
                            ref enumWbem);
                    }

                    if (status >= 0)
                    {
                        if ((cachedCount - cacheIndex) == 0) //cache is empty - need to get more objects
                        {
#if true
                            //Because Interop doesn't support custom marshalling for arrays, we have to use
                            //the "DoNotMarshal" objects in the interop and then convert to the "FreeThreaded"
                            //counterparts afterwards.
                            IWbemClassObject_DoNotMarshal[] tempArray = new IWbemClassObject_DoNotMarshal[options.BlockSize];

                            int timeout = (ManagementOptions.InfiniteTimeout == options.Timeout)
                                ? (int) tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE :
                                (int) options.Timeout.TotalMilliseconds;
                            
                            status = scope.GetSecuredIEnumWbemClassObjectHandler(enumWbem).Next_(timeout, (uint)options.BlockSize, tempArray, ref cachedCount);
                            cacheIndex = 0;

                            if (status >= 0)
                            {
                                //Convert results and put them in cache. Note that we may have timed out
                                //in which case we might not have all the objects. If no object can be returned
                                //we throw a timeout exception... - 

                                if (cachedCount == 0)
                                    ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);

                                for (int i = 0; i < cachedCount; i++)
                                    cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(tempArray[i]));
                            }

#else
                            //This was workaround when using TLBIMP we couldn't pass in arrays...

                            IWbemClassObjectFreeThreaded cachedObject = cachedObjects[0];
                            int timeout = (ManagementOptions.InfiniteTimeout == options.Timeout)
                                ? (int) tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE :
                                (int) options.Timeout.TotalMilliseconds;
                            status = scope.GetSecuredIEnumWbemClassObjectHandler(enumWbem).Next_(timeout, 1, out cachedObjects, out cachedCount);

                            cacheIndex = 0;

                            if (status >= 0)
                            {
                                //Create ManagementObject for result. Note that we may have timed out
                                //in which case we won't have an object
                                if (null == cachedObject)
                                    ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);

                                cachedObjects[0] = cachedObject;
                            }
#endif
                        }

                        if (status >= 0)
                        {
                            obj = new ManagementBaseObject(cachedObjects[cacheIndex]);
                            cacheIndex++;
                        }
                    }
                } 
                finally 
                {
                    securityHandler.Reset();
                }

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

            return obj;
        }
예제 #28
0
		int System.Management.IWbemServices_Old.PutInstanceAsync_(IWbemClassObject_DoNotMarshal pInst, int lFlags, IWbemContext pCtx, IWbemObjectSink pResponseHandler)
		{
			return -2147217396;
		}
예제 #29
0
		public virtual int SpawnDerivedClass_ (int lFlags, out IWbemClassObject_DoNotMarshal ppNewClass)
		{
			ppNewClass = this;
			return 0;
		}
        internal static object MapValueToWmiValue(object val, out bool isArray, out CimType type)
        {
            object      objectForIUnknown = DBNull.Value;
            CultureInfo invariantCulture  = CultureInfo.InvariantCulture;

            isArray = false;
            type    = CimType.None;
            if (val != null)
            {
                isArray = val.GetType().IsArray;
                System.Type type2 = val.GetType();
                if (isArray)
                {
                    System.Type elementType = type2.GetElementType();
                    if (elementType.IsPrimitive)
                    {
                        if (elementType == typeof(byte))
                        {
                            byte[] buffer = (byte[])val;
                            int    length = buffer.Length;
                            type = CimType.UInt8;
                            objectForIUnknown = new short[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((short[])objectForIUnknown)[i] = ((IConvertible)buffer[i]).ToInt16(null);
                            }
                            return(objectForIUnknown);
                        }
                        if (elementType == typeof(sbyte))
                        {
                            sbyte[] numArray = (sbyte[])val;
                            int     num3     = numArray.Length;
                            type = CimType.SInt8;
                            objectForIUnknown = new short[num3];
                            for (int j = 0; j < num3; j++)
                            {
                                ((short[])objectForIUnknown)[j] = ((IConvertible)numArray[j]).ToInt16(null);
                            }
                            return(objectForIUnknown);
                        }
                        if (elementType == typeof(bool))
                        {
                            type = CimType.Boolean;
                            return((bool[])val);
                        }
                        if (elementType == typeof(ushort))
                        {
                            ushort[] numArray2 = (ushort[])val;
                            int      num5      = numArray2.Length;
                            type = CimType.UInt16;
                            objectForIUnknown = new int[num5];
                            for (int k = 0; k < num5; k++)
                            {
                                ((int[])objectForIUnknown)[k] = ((IConvertible)numArray2[k]).ToInt32(null);
                            }
                            return(objectForIUnknown);
                        }
                        if (elementType == typeof(short))
                        {
                            type = CimType.SInt16;
                            return((short[])val);
                        }
                        if (elementType == typeof(int))
                        {
                            type = CimType.SInt32;
                            return((int[])val);
                        }
                        if (elementType == typeof(uint))
                        {
                            uint[] numArray3 = (uint[])val;
                            int    num7      = numArray3.Length;
                            type = CimType.UInt32;
                            objectForIUnknown = new string[num7];
                            for (int m = 0; m < num7; m++)
                            {
                                ((string[])objectForIUnknown)[m] = numArray3[m].ToString((IFormatProvider)invariantCulture.GetFormat(typeof(uint)));
                            }
                            return(objectForIUnknown);
                        }
                        if (elementType == typeof(ulong))
                        {
                            ulong[] numArray4 = (ulong[])val;
                            int     num9      = numArray4.Length;
                            type = CimType.UInt64;
                            objectForIUnknown = new string[num9];
                            for (int n = 0; n < num9; n++)
                            {
                                ((string[])objectForIUnknown)[n] = numArray4[n].ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
                            }
                            return(objectForIUnknown);
                        }
                        if (elementType == typeof(long))
                        {
                            long[] numArray5 = (long[])val;
                            int    num11     = numArray5.Length;
                            type = CimType.SInt64;
                            objectForIUnknown = new string[num11];
                            for (int num12 = 0; num12 < num11; num12++)
                            {
                                ((string[])objectForIUnknown)[num12] = numArray5[num12].ToString((IFormatProvider)invariantCulture.GetFormat(typeof(long)));
                            }
                            return(objectForIUnknown);
                        }
                        if (elementType == typeof(float))
                        {
                            type = CimType.Real32;
                            return((float[])val);
                        }
                        if (elementType == typeof(double))
                        {
                            type = CimType.Real64;
                            return((double[])val);
                        }
                        if (elementType == typeof(char))
                        {
                            char[] chArray = (char[])val;
                            int    num13   = chArray.Length;
                            type = CimType.Char16;
                            objectForIUnknown = new short[num13];
                            for (int num14 = 0; num14 < num13; num14++)
                            {
                                ((short[])objectForIUnknown)[num14] = ((IConvertible)chArray[num14]).ToInt16(null);
                            }
                        }
                        return(objectForIUnknown);
                    }
                    if (elementType == typeof(string))
                    {
                        type = CimType.String;
                        return((string[])val);
                    }
                    if (val is ManagementBaseObject[])
                    {
                        Array array = (Array)val;
                        int   num15 = array.Length;
                        type = CimType.Object;
                        objectForIUnknown = new IWbemClassObject_DoNotMarshal[num15];
                        for (int num16 = 0; num16 < num15; num16++)
                        {
                            ((IWbemClassObject_DoNotMarshal[])objectForIUnknown)[num16] = (IWbemClassObject_DoNotMarshal)Marshal.GetObjectForIUnknown((IntPtr)((ManagementBaseObject)array.GetValue(num16)).wbemObject);
                        }
                    }
                    return(objectForIUnknown);
                }
                if (type2 == typeof(ushort))
                {
                    type = CimType.UInt16;
                    return(((IConvertible)((ushort)val)).ToInt32(null));
                }
                if (type2 == typeof(uint))
                {
                    type = CimType.UInt32;
                    if ((((uint)val) & 0x80000000) != 0)
                    {
                        return(Convert.ToString(val, (IFormatProvider)invariantCulture.GetFormat(typeof(uint))));
                    }
                    return(Convert.ToInt32(val, (IFormatProvider)invariantCulture.GetFormat(typeof(int))));
                }
                if (type2 == typeof(ulong))
                {
                    type = CimType.UInt64;
                    ulong num17 = (ulong)val;
                    return(num17.ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong))));
                }
                if (type2 == typeof(sbyte))
                {
                    type = CimType.SInt8;
                    return(((IConvertible)((sbyte)val)).ToInt16(null));
                }
                if (type2 == typeof(byte))
                {
                    type = CimType.UInt8;
                    return(val);
                }
                if (type2 == typeof(short))
                {
                    type = CimType.SInt16;
                    return(val);
                }
                if (type2 == typeof(int))
                {
                    type = CimType.SInt32;
                    return(val);
                }
                if (type2 == typeof(long))
                {
                    type = CimType.SInt64;
                    return(val.ToString());
                }
                if (type2 == typeof(bool))
                {
                    type = CimType.Boolean;
                    return(val);
                }
                if (type2 == typeof(float))
                {
                    type = CimType.Real32;
                    return(val);
                }
                if (type2 == typeof(double))
                {
                    type = CimType.Real64;
                    return(val);
                }
                if (type2 == typeof(char))
                {
                    type = CimType.Char16;
                    return(((IConvertible)((char)val)).ToInt16(null));
                }
                if (type2 == typeof(string))
                {
                    type = CimType.String;
                    return(val);
                }
                if (val is ManagementBaseObject)
                {
                    type = CimType.Object;
                    objectForIUnknown = Marshal.GetObjectForIUnknown((IntPtr)((ManagementBaseObject)val).wbemObject);
                }
            }
            return(objectForIUnknown);
        }
예제 #31
0
		public virtual int SpawnInstance_ (int lFlags, out IWbemClassObject_DoNotMarshal ppNewInstance)
		{
			ppNewInstance = this;
			return 0;
		}
            public bool MoveNext()
            {
                int totalMilliseconds;

                if (!this.isDisposed)
                {
                    if (!this.atEndOfCollection)
                    {
                        ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator = this;
                        managementObjectEnumerator.cacheIndex = managementObjectEnumerator.cacheIndex + 1;
                        if ((long)this.cachedCount - (long)this.cacheIndex == (long)0)
                        {
                            TimeSpan timeout = this.collectionObject.options.Timeout;
                            if (timeout.Ticks == 0x7fffffffffffffffL)
                            {
                                totalMilliseconds = -1;
                            }
                            else
                            {
                                TimeSpan timeSpan = this.collectionObject.options.Timeout;
                                totalMilliseconds = (int)timeSpan.TotalMilliseconds;
                            }
                            int             num             = totalMilliseconds;
                            SecurityHandler securityHandler = this.collectionObject.scope.GetSecurityHandler();
                            IWbemClassObject_DoNotMarshal[] wbemClassObjectDoNotMarshalArray = new IWbemClassObject_DoNotMarshal[this.collectionObject.options.BlockSize];
                            int num1 = this.collectionObject.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(num, this.collectionObject.options.BlockSize, wbemClassObjectDoNotMarshalArray, ref this.cachedCount);
                            securityHandler.Reset();
                            if (num1 >= 0)
                            {
                                for (int i = 0; (long)i < (long)this.cachedCount; i++)
                                {
                                    IntPtr ptr = Marshal.GetIUnknownForObject(wbemClassObjectDoNotMarshalArray[i].NativeObject);
                                    this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(ptr);
                                }
                            }
                            if (num1 >= 0)
                            {
                                if (num1 == 0x40004 && this.cachedCount == 0)
                                {
                                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)num1);
                                }
                                if (num1 == 1 && this.cachedCount == 0)
                                {
                                    this.atEndOfCollection = true;
                                    ManagementObjectCollection.ManagementObjectEnumerator managementObjectEnumerator1 = this;
                                    managementObjectEnumerator1.cacheIndex = managementObjectEnumerator1.cacheIndex - 1;
                                    return(false);
                                }
                            }
                            else
                            {
                                if (((long)num1 & (long)-4096) != (long)-2147217408)
                                {
                                    Marshal.ThrowExceptionForHR(num1);
                                }
                                else
                                {
                                    ManagementException.ThrowWithExtendedInfo((ManagementStatus)num1);
                                }
                            }
                            this.cacheIndex = 0;
                        }
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    throw new ObjectDisposedException(ManagementObjectCollection.ManagementObjectEnumerator.name);
                }
            }
예제 #33
0
		public static IntPtr ToPointer (IWbemClassObject_DoNotMarshal obj)
		{
			return Marshal.GetIUnknownForObject(obj.NativeObject);
		}
예제 #34
0
		/// <summary>
		/// Takes a managed code value, together with a desired property 
		/// </summary>
		/// <param name="val"> </param>
		/// <param name="type"> </param>
		/// <param name="isArray"> </param>
		internal static object MapValueToWmiValue(object val, CimType type, bool isArray)
		{
			object wmiValue = System.DBNull.Value;
			CultureInfo culInfo = CultureInfo.InvariantCulture;
			if (null != val)
			{
				if (isArray)
				{
					Array valArray = (Array)val;
					int length = valArray.Length;

					switch (type)
					{
						case CimType.SInt8:
							wmiValue = new Int16 [length];
							for (int i = 0; i < length; i++)
								((Int16[])(wmiValue))[i] = (Int16)Convert.ToSByte(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.SByte)));
							break;

						case CimType.UInt8: 
							if (val is Byte[])
								wmiValue = val;
							else
							{
								wmiValue = new Byte [length];
								for (int i = 0; i < length; i++)
									((Byte[])wmiValue)[i] = Convert.ToByte(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Byte)));
							}
							break;

						case CimType.SInt16:
							if (val is Int16[])
								wmiValue = val;
							else
							{
								wmiValue = new Int16 [length];
								for (int i = 0; i < length; i++)
									((Int16[])(wmiValue))[i] = Convert.ToInt16(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Int16)));
							}
							break;

						case CimType.UInt16:
							wmiValue = new Int32 [length];
							for (int i = 0; i < length; i++)
								((Int32[])(wmiValue))[i] = (Int32)(Convert.ToUInt16(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.UInt16))));
							break;

						case CimType.SInt32:
							if (val is Int32[])
								wmiValue = val;
							else
							{
								wmiValue = new Int32 [length];
								for (int i = 0; i < length; i++)
									((Int32[])(wmiValue))[i] = Convert.ToInt32(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Int32)));
							}				
							break;

						case CimType.UInt32:
							wmiValue = new Int32 [length];
							for (int i = 0; i < length; i++)
								((Int32[])(wmiValue))[i] = (Int32)(Convert.ToUInt32(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.UInt32))));
							break;

						case CimType.SInt64:
							wmiValue = new String [length];
							for (int i = 0; i < length; i++)
								((String[])(wmiValue))[i] = (Convert.ToInt64(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Int64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.Int64)));
							break;

						case CimType.UInt64:
							wmiValue = new String [length];
							for (int i = 0; i < length; i++)
								((String[])(wmiValue))[i] = (Convert.ToUInt64(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)));
							break;

						case CimType.Real32:
							if (val is Single[])
								wmiValue = val;
							else
							{
								wmiValue = new Single [length];
								for (int i = 0; i < length; i++)
									((Single[])(wmiValue))[i] = Convert.ToSingle(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Single)));
							}				
							break;

						case CimType.Real64:
							if (val is Double[])
								wmiValue = val;
							else
							{
								wmiValue = new Double [length];
								for (int i = 0; i < length; i++)
									((Double[])(wmiValue))[i] = Convert.ToDouble(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Double)));
							}				
							break;

						case CimType.Char16: 
							wmiValue = new Int16 [length];
							for (int i = 0; i < length; i++)
								((Int16[])(wmiValue))[i] = (Int16)Convert.ToChar(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Char)));
							break;

						case CimType.String:
						case CimType.DateTime:
						case CimType.Reference:
							if (val is String[])
								wmiValue = val;
							else
							{
								wmiValue = new String [length];
								for (int i = 0; i < length; i++)
									((String[])(wmiValue))[i] = (valArray.GetValue(i)).ToString();
							}
							break;

						case CimType.Boolean:
							if (val is Boolean[])
								wmiValue = val;
							else
							{
								wmiValue = new Boolean [length];
								for (int i = 0; i < length; i++)
									((Boolean[])(wmiValue))[i] = Convert.ToBoolean(valArray.GetValue(i),(IFormatProvider)culInfo.GetFormat(typeof(System.Boolean)));
							}
							break;

						case CimType.Object:
							wmiValue = new IWbemClassObject_DoNotMarshal[length];

							for (int i = 0; i < length; i++)
							{
								//
								// Removed below Initialize call since wbemObject is a property that will call Initialize ( true ) on
								// its getter.
								//
								//((ManagementBaseObject)valArray.GetValue(i)).Initialize ( false ) ;
								((IWbemClassObject_DoNotMarshal[])(wmiValue))[i] = (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(((ManagementBaseObject)valArray.GetValue(i)).wbemObject));
							}
							break;

						default:
							wmiValue = val;
							break;
					}
				}
				else
				{
					switch (type)
					{
						case CimType.SInt8:
							wmiValue = (Int16)Convert.ToSByte(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Int16)));
							break;

						case CimType.UInt8:
							wmiValue = Convert.ToByte(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Byte)));
							break;

						case CimType.SInt16:
							wmiValue = Convert.ToInt16(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Int16))); 
							break;

						case CimType.UInt16:
							wmiValue = (Int32)(Convert.ToUInt16(val,(IFormatProvider)culInfo.GetFormat(typeof(System.UInt16))));
							break;

						case CimType.SInt32:
							wmiValue = Convert.ToInt32(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Int32))); 
							break;

						case CimType.UInt32:
							wmiValue = (Int32)Convert.ToUInt32(val,(IFormatProvider)culInfo.GetFormat(typeof(System.UInt32)));
							break;

						case CimType.SInt64:
							wmiValue = (Convert.ToInt64(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Int64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.Int64)));
							break;

						case CimType.UInt64:
							wmiValue = (Convert.ToUInt64(val,(IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)));
							break;

						case CimType.Real32:
							wmiValue = Convert.ToSingle(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Single)));
							break;

						case CimType.Real64:
							wmiValue = Convert.ToDouble(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Double)));
							break;

						case CimType.Char16:
							wmiValue = (Int16)Convert.ToChar(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Char)));
							break;

						case CimType.String:
						case CimType.DateTime:
						case CimType.Reference:
							wmiValue = val.ToString();
							break;

						case CimType.Boolean:
							wmiValue = Convert.ToBoolean(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Boolean)));
							break;

						case CimType.Object:
							if (val is ManagementBaseObject)
							{
								//
								// Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
								// its getter.
								//
								//((ManagementBaseObject)val).Initialize ( false ) ;
								wmiValue = Marshal.GetObjectForIUnknown(((ManagementBaseObject) val).wbemObject);
							}
							else
							{
								//Debug.Assert(false, "Unhandled object type");
								wmiValue = val;
							}
							break;

						default:
							wmiValue = val;
							break;
					}
				}
			}

			return wmiValue;
		}
예제 #35
0
		internal static object MapValueToWmiValue(object val, CimType type, bool isArray)
		{
			object value = DBNull.Value;
			CultureInfo invariantCulture = CultureInfo.InvariantCulture;
			if (val != null)
			{
				if (!isArray)
				{
					CimType cimType = type;
					switch (cimType)
					{
						case CimType.SInt16:
						{
							value = Convert.ToInt16(val, (IFormatProvider)invariantCulture.GetFormat(typeof(short)));
							break;
						}
						case CimType.SInt32:
						{
							value = Convert.ToInt32(val, (IFormatProvider)invariantCulture.GetFormat(typeof(int)));
							break;
						}
						case CimType.Real32:
						{
							value = Convert.ToSingle(val, (IFormatProvider)invariantCulture.GetFormat(typeof(float)));
							break;
						}
						case CimType.Real64:
						{
							value = Convert.ToDouble(val, (IFormatProvider)invariantCulture.GetFormat(typeof(double)));
							break;
						}
						case CimType.SInt16 | CimType.Real32:
						case CimType.SInt16 | CimType.SInt32 | CimType.Real32 | CimType.Real64:
						/*case 9: */
						case CimType.SInt16 | CimType.String:
						case CimType.Real32 | CimType.String:
						case CimType.SInt16 | CimType.Real32 | CimType.String:
						case CimType.SInt16 | CimType.SInt32 | CimType.Real32 | CimType.Real64 | CimType.Boolean | CimType.String | CimType.Object:
						{
							value = val;
							break;
						}
						case CimType.String:
						{
							value = val.ToString();
							break;
						}
						case CimType.Boolean:
						{
							value = Convert.ToBoolean(val, (IFormatProvider)invariantCulture.GetFormat(typeof(bool)));
							break;
						}
						case CimType.Object:
						{
							if (val as ManagementBaseObject == null)
							{
								value = val;
								break;
							}
							else
							{
								value = Marshal.GetObjectForIUnknown(((ManagementBaseObject)val).wbemObject);
								break;
							}
						}
						case CimType.SInt8:
						{
							value = (short)Convert.ToSByte(val, (IFormatProvider)invariantCulture.GetFormat(typeof(short)));
							break;
						}
						case CimType.UInt8:
						{
							value = Convert.ToByte(val, (IFormatProvider)invariantCulture.GetFormat(typeof(byte)));
							break;
						}
						case CimType.UInt16:
						{
							value = (int)Convert.ToUInt16(val, (IFormatProvider)invariantCulture.GetFormat(typeof(ushort)));
							break;
						}
						case CimType.UInt32:
						{
							value = (int)Convert.ToUInt32(val, (IFormatProvider)invariantCulture.GetFormat(typeof(uint)));
							break;
						}
						case CimType.SInt64:
						{
							long num = Convert.ToInt64(val, (IFormatProvider)invariantCulture.GetFormat(typeof(long)));
							value = num.ToString((IFormatProvider)invariantCulture.GetFormat(typeof(long)));
							break;
						}
						case CimType.UInt64:
						{
							ulong num1 = Convert.ToUInt64(val, (IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
							value = num1.ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
							break;
						}
						default:
						{
							if (cimType == CimType.DateTime || cimType == CimType.Reference)
							{
								value = val.ToString();
								break;
							}
							else if (cimType == CimType.Char16)
							{
								value = (short)Convert.ToChar(val, (IFormatProvider)invariantCulture.GetFormat(typeof(char)));
								break;
							}
							value = val;
							break;
						}
					}
				}
				else
				{
					Array arrays = (Array)val;
					int length = arrays.Length;
					CimType cimType1 = type;
					switch (cimType1)
					{
						case CimType.SInt16:
						{
							if (val as short[] == null)
							{
								value = new short[length];
								for (int i = 0; i < length; i++)
								{
									((short[])value)[i] = Convert.ToInt16(arrays.GetValue(i), (IFormatProvider)invariantCulture.GetFormat(typeof(short)));
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.SInt32:
						{
							if (val as int[] == null)
							{
								value = new int[length];
								for (int j = 0; j < length; j++)
								{
									((int[])value)[j] = Convert.ToInt32(arrays.GetValue(j), (IFormatProvider)invariantCulture.GetFormat(typeof(int)));
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.Real32:
						{
							if (val as float[] == null)
							{
								value = new float[length];
								for (int k = 0; k < length; k++)
								{
									((float[])value)[k] = Convert.ToSingle(arrays.GetValue(k), (IFormatProvider)invariantCulture.GetFormat(typeof(float)));
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.Real64:
						{
							if (val as double[] == null)
							{
								value = new double[length];
								for (int l = 0; l < length; l++)
								{
									((double[])value)[l] = Convert.ToDouble(arrays.GetValue(l), (IFormatProvider)invariantCulture.GetFormat(typeof(double)));
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.SInt16 | CimType.Real32:
						case CimType.SInt16 | CimType.SInt32 | CimType.Real32 | CimType.Real64:
						/*case 9: */
						case CimType.SInt16 | CimType.String:
						case CimType.Real32 | CimType.String:
						case CimType.SInt16 | CimType.Real32 | CimType.String:
						case CimType.SInt16 | CimType.SInt32 | CimType.Real32 | CimType.Real64 | CimType.Boolean | CimType.String | CimType.Object:
						{
							value = val;
							break;
						}
						case CimType.String:
						{
							if (val as string[] == null)
							{
								value = new string[length];
								for (int m = 0; m < length; m++)
								{
									((string[])value)[m] = arrays.GetValue(m).ToString();
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.Boolean:
						{
							if (val as bool[] == null)
							{
								value = new bool[length];
								for (int n = 0; n < length; n++)
								{
									((bool[])value)[n] = Convert.ToBoolean(arrays.GetValue(n), (IFormatProvider)invariantCulture.GetFormat(typeof(bool)));
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.Object:
						{
							value = new IWbemClassObject_DoNotMarshal[length];
							for (int o = 0; o < length; o++)
							{
								((IWbemClassObject_DoNotMarshal[])value)[o] = (IWbemClassObject_DoNotMarshal)Marshal.GetObjectForIUnknown(((ManagementBaseObject)arrays.GetValue(o)).wbemObject);
							}
							break;
						}
						case CimType.SInt8:
						{
							value = new short[length];
							for (int p = 0; p < length; p++)
							{
								((short[])value)[p] = Convert.ToSByte(arrays.GetValue(p), (IFormatProvider)invariantCulture.GetFormat(typeof(sbyte)));
							}
							break;
						}
						case CimType.UInt8:
						{
							if (val as byte[] == null)
							{
								value = new byte[length];
								for (int q = 0; q < length; q++)
								{
									((byte[])value)[q] = Convert.ToByte(arrays.GetValue(q), (IFormatProvider)invariantCulture.GetFormat(typeof(byte)));
								}
								break;
							}
							else
							{
								value = val;
								break;
							}
						}
						case CimType.UInt16:
						{
							value = new int[length];
							for (int r = 0; r < length; r++)
							{
								((int[])value)[r] = Convert.ToUInt16(arrays.GetValue(r), (IFormatProvider)invariantCulture.GetFormat(typeof(ushort)));
							}
							break;
						}
						case CimType.UInt32:
						{
							value = new int[length];
							for (int s = 0; s < length; s++)
							{
								((uint[])value)[s] = Convert.ToUInt32(arrays.GetValue(s), (IFormatProvider)invariantCulture.GetFormat(typeof(uint)));
							}
							break;
						}
						case CimType.SInt64:
						{
							value = new string[length];
							for (int t = 0; t < length; t++)
							{
								long num2 = Convert.ToInt64(arrays.GetValue(t), (IFormatProvider)invariantCulture.GetFormat(typeof(long)));
								((string[])value)[t] = num2.ToString((IFormatProvider)invariantCulture.GetFormat(typeof(long)));
							}
							break;
						}
						case CimType.UInt64:
						{
							value = new string[length];
							for (int u = 0; u < length; u++)
							{
								ulong num3 = Convert.ToUInt64(arrays.GetValue(u), (IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
								((string[])value)[u] = num3.ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
							}
							break;
						}
						default:
						{
							if (cimType1 == CimType.DateTime || cimType1 == CimType.Reference)
							{
								if (val as string[] == null)
								{
									value = new string[length];
									for (int m = 0; m < length; m++)
									{
										((string[])value)[m] = arrays.GetValue(m).ToString();
									}
									break;
								}
								else
								{
									value = val;
									break;
								}
							}
							else if (cimType1 == CimType.Char16)
							{
								value = new short[length];
								for (int v = 0; v < length; v++)
								{
									((short[])value)[v] = (short)Convert.ToChar(arrays.GetValue(v), (IFormatProvider)invariantCulture.GetFormat(typeof(char)));
								}
								break;
							}
							value = val;
							break;
						}
					}
				}
			}
			return value;
		}
예제 #36
0
 internal int Next_( int lTimeout, uint uCount, IWbemClassObject_DoNotMarshal[] ppOutParams, ref uint puReturned)
 {
     int status = (int)tag_WBEMSTATUS.WBEM_E_FAILED;
     status = pEnumWbemClassObjectsecurityHelper.Next_( lTimeout, uCount,  ppOutParams, out puReturned);
     return status;
 }
예제 #37
0
		internal static object MapValueToWmiValue(object val, out bool isArray, out CimType type)
		{
			object wmiValue = System.DBNull.Value;
			CultureInfo culInfo = CultureInfo.InvariantCulture;
			isArray = false;
			type = 0;
			
			if (null != val)
			{
				isArray = val.GetType().IsArray;
				Type valueType = val.GetType();

				if (isArray)
				{
					Type elementType = valueType.GetElementType();

					// Casting primitive types to object[] is not allowed
					if (elementType.IsPrimitive)
					{
						if (elementType == typeof(System.Byte))
						{
							byte[] arrayValue = (byte[])val;
							int length = arrayValue.Length;
							type = CimType.UInt8;
							wmiValue = new short[length];

							for (int i = 0; i < length; i++)
								((short[])wmiValue) [i] = ((IConvertible)((System.Byte)(arrayValue[i]))).ToInt16(null);
						}
						else if (elementType == typeof(System.SByte))
						{
							sbyte[] arrayValue = (sbyte[])val;
							int length = arrayValue.Length;
							type = CimType.SInt8;
							wmiValue = new short[length];

							for (int i = 0; i < length; i++)
								((short[])wmiValue) [i] = ((IConvertible)((System.SByte)(arrayValue[i]))).ToInt16(null);
						}
						else if (elementType == typeof(System.Boolean))
						{
							type = CimType.Boolean;
							wmiValue = (bool[])val;
						}					
						else if (elementType == typeof(System.UInt16))
						{
							ushort[] arrayValue = (ushort[])val;
							int length = arrayValue.Length;
							type = CimType.UInt16;
							wmiValue = new int[length];

							for (int i = 0; i < length; i++)
								((int[])wmiValue) [i] = ((IConvertible)((System.UInt16)(arrayValue[i]))).ToInt32(null);
						}
						else if (elementType == typeof(System.Int16))
						{
							type = CimType.SInt16;
							wmiValue = (short[])val;
						}
						else if (elementType == typeof(System.Int32))
						{
							type = CimType.SInt32;
							wmiValue = (int[])val;
						}
						else if (elementType == typeof(System.UInt32))
						{
							uint[] arrayValue = (uint[])val;
							int length = arrayValue.Length;
							type = CimType.UInt32;
							wmiValue = new string[length];

							for (int i = 0; i < length; i++)
								((string[])wmiValue) [i] = ((System.UInt32)(arrayValue[i])).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt32)));
						}
						else if (elementType == typeof(System.UInt64))
						{
							ulong[] arrayValue = (ulong[])val;
							int length = arrayValue.Length;
							type = CimType.UInt64;
							wmiValue = new string[length];

							for (int i = 0; i < length; i++)
								((string[])wmiValue) [i] = ((System.UInt64)(arrayValue[i])).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)));
						}
						else if (elementType == typeof(System.Int64))
						{
							long[] arrayValue = (long[])val;
							int length = arrayValue.Length;
							type = CimType.SInt64;
							wmiValue = new string[length];

							for (int i = 0; i < length; i++)
								((string[])wmiValue) [i] = ((long)(arrayValue[i])).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.Int64)));
						}
						else if (elementType == typeof(System.Single))
						{
							type = CimType.Real32;
							wmiValue = (System.Single[])val;
						}
						else if (elementType == typeof(System.Double))
						{
							type = CimType.Real64;
							wmiValue = (double[])val;
						}
						else if (elementType == typeof(System.Char))
						{
							char[] arrayValue = (char[])val;
							int length = arrayValue.Length;
							type = CimType.Char16;
							wmiValue = new short[length];

							for (int i = 0; i < length; i++)
								((short[])wmiValue) [i] = ((IConvertible)((System.Char)(arrayValue[i]))).ToInt16(null);
						}
					}
					else
					{
						// Non-primitive types
						if (elementType == typeof(System.String))
						{
							type = CimType.String;
							wmiValue = (string[])val;
						}
						else
						{
							// Check for an embedded object array
							if (val is ManagementBaseObject[])
							{
								Array valArray = (Array)val;
								int length = valArray.Length;
								type = CimType.Object;
								wmiValue = new IWbemClassObject_DoNotMarshal[length];

								for (int i = 0; i < length; i++)
								{
									//
									// Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
									// its getter.
									//
									//((ManagementBaseObject)valArray.GetValue(i)).Initialize ( false ) ;
									((IWbemClassObject_DoNotMarshal[])(wmiValue))[i] = (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(((ManagementBaseObject)valArray.GetValue(i)).wbemObject));
								}
							}
						}
					}
				}
				else	// Non-array values
				{
					if (valueType == typeof(System.UInt16))
					{
						type = CimType.UInt16;
						wmiValue = ((IConvertible)((System.UInt16)val)).ToInt32(null);
					}
					else if (valueType == typeof(System.UInt32))
					{
						type = CimType.UInt32;
						if (((System.UInt32)val & 0x80000000) != 0)
							wmiValue = Convert.ToString(val,(IFormatProvider)culInfo.GetFormat(typeof(System.UInt32)));
						else
							wmiValue = Convert.ToInt32(val,(IFormatProvider)culInfo.GetFormat(typeof(System.Int32)));
					}
					else if (valueType == typeof(System.UInt64))
					{
						type = CimType.UInt64;
						wmiValue = ((System.UInt64)val).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)));
					}
					else if (valueType == typeof(System.SByte))
					{
						type = CimType.SInt8;
						wmiValue = ((IConvertible)((System.SByte)val)).ToInt16(null);
					}
					else if (valueType == typeof(System.Byte))
					{
                        type = CimType.UInt8;
						wmiValue = val;
					}
					else if (valueType == typeof(System.Int16))
					{
						type = CimType.SInt16;
						wmiValue = val;
					}
					else if (valueType == typeof(System.Int32))
					{
						type = CimType.SInt32;
						wmiValue = val;
					}
					else if (valueType == typeof(System.Int64))
					{
						type = CimType.SInt64;
						wmiValue = val.ToString();
					}
					else if (valueType == typeof(System.Boolean))
					{
						type = CimType.Boolean;
						wmiValue = val;
					}
					else if (valueType == typeof(System.Single))
					{
						type = CimType.Real32;
						wmiValue = val;
					}
					else if (valueType == typeof(System.Double))
					{
						type = CimType.Real64;
						wmiValue = val;
					}
					else if (valueType == typeof(System.Char))
					{
						type = CimType.Char16;
						wmiValue = ((IConvertible)((System.Char)val)).ToInt16(null);
					}
					else if (valueType == typeof(System.String))
					{
						type = CimType.String;
						wmiValue = val;
					}
					else
					{
						// Check for an embedded object
						if (val is ManagementBaseObject)
						{
							type = CimType.Object;
							//
							// Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
							// its getter.
							//
							//((ManagementBaseObject)val).Initialize ( false ) ;
							wmiValue = Marshal.GetObjectForIUnknown(((ManagementBaseObject) val).wbemObject);
						}
					}
				}
			}

			return wmiValue;
		}
예제 #38
0
 int System.Management.IWbemServices_Old.ExecMethodAsync_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObject_DoNotMarshal pInParams, IWbemObjectSink pResponseHandler)
 {
     return(-2147217396);
 }
예제 #39
0
            //****************************************
            //MoveNext
            //****************************************
            /// <summary>
            ///    Indicates whether the enumerator has moved to
            ///    the next object in the enumeration.
            /// </summary>
            /// <returns>
            /// <para><see langword='true'/>, if the enumerator was 
            ///    successfully advanced to the next element; <see langword='false'/> if the enumerator has
            ///    passed the end of the collection.</para>
            /// </returns>
            public bool MoveNext ()
            {
                if (isDisposed)
                    throw new ObjectDisposedException(name);
                
                //If there are no more objects in the collection return false
                if (atEndOfCollection) 
                    return false;

                //Look for the next object
                cacheIndex++;

                if ((cachedCount - cacheIndex) == 0) //cache is empty - need to get more objects
                {

                    //If the timeout is set to infinite, need to use the WMI infinite constant
                    int timeout = (collectionObject.options.Timeout.Ticks == Int64.MaxValue) ? 
                        (int)tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE : (int)collectionObject.options.Timeout.TotalMilliseconds;

                    //Get the next [BLockSize] objects within the specified timeout
                    // 

                    SecurityHandler securityHandler = collectionObject.scope.GetSecurityHandler();

                    //Because Interop doesn't support custom marshalling for arrays, we have to use
                    //the "DoNotMarshal" objects in the interop and then convert to the "FreeThreaded"
                    //counterparts afterwards.
                    IWbemClassObject_DoNotMarshal[] tempArray = new IWbemClassObject_DoNotMarshal[collectionObject.options.BlockSize];

                    int status = collectionObject.scope.GetSecuredIEnumWbemClassObjectHandler(enumWbem ).Next_(timeout, (uint)collectionObject.options.BlockSize,tempArray, ref cachedCount);

                    securityHandler.Reset();

                    if (status >= 0)
                    {
                        //Convert results and put them in cache.

                        for (int i = 0; i < cachedCount; i++)
                        {
                            cachedObjects[i] = new IWbemClassObjectFreeThreaded
                                                (
                                                    Marshal.GetIUnknownForObject(tempArray[i])
                                                );
                        }
                    }

                    if (status < 0)
                    {
                        if ((status & 0xfffff000) == 0x80041000)
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);
                        else
                            Marshal.ThrowExceptionForHR(status);
                    }
                    else
                    {
                        //If there was a timeout and no object can be returned we throw a timeout exception... 
                        // - 
                        if ((status == (int)tag_WBEMSTATUS.WBEM_S_TIMEDOUT) && (cachedCount == 0))
                            ManagementException.ThrowWithExtendedInfo((ManagementStatus)status);

                        //If not timeout and no objects were returned - we're at the end of the collection
                        if ((status == (int)tag_WBEMSTATUS.WBEM_S_FALSE) && (cachedCount == 0))
                        {
                            atEndOfCollection = true;
                            cacheIndex--; //back to last object

                            /* This call to Dispose is being removed as per discussion with URT people and the newly supported
                             * Dispose() call in the foreach implementation itself.
                             * 
                             *                              //Release the COM object (so that the user doesn't have to)
                                                            Dispose();
                            */
                            return false;
                        }
                    }

                    cacheIndex = 0;
                }

                return true;
            }
예제 #40
0
 int System.Management.IWbemServices_Old.PutInstance_(IWbemClassObject_DoNotMarshal pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult)
 {
     return(-2147217396);
 }
예제 #41
0
		int System.Management.IWbemServices_Old.ExecMethod_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObject_DoNotMarshal pInParams, out IWbemClassObject_DoNotMarshal ppOutParams, IntPtr ppCallResult)
		{
			ppOutParams = null;
			return -2147217396;
		}
        internal static object MapValueToWmiValue(object val, CimType type, bool isArray)
        {
            object obj2 = DBNull.Value;
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;
            if (val == null)
            {
                return obj2;
            }
            if (!isArray)
            {
                switch (type)
                {
                    case CimType.SInt16:
                        return Convert.ToInt16(val, (IFormatProvider) invariantCulture.GetFormat(typeof(short)));

                    case CimType.SInt32:
                        return Convert.ToInt32(val, (IFormatProvider) invariantCulture.GetFormat(typeof(int)));

                    case CimType.Real32:
                        return Convert.ToSingle(val, (IFormatProvider) invariantCulture.GetFormat(typeof(float)));

                    case CimType.Real64:
                        return Convert.ToDouble(val, (IFormatProvider) invariantCulture.GetFormat(typeof(double)));

                    case (CimType.Real32 | CimType.SInt16):
                    case (CimType.Real64 | CimType.SInt16):
                    case ((CimType) 9):
                    case (CimType.String | CimType.SInt16):
                    case (CimType.String | CimType.Real32):
                    case (CimType.String | CimType.Real32 | CimType.SInt16):
                    case (CimType.Object | CimType.SInt16):
                        return val;

                    case CimType.String:
                    case CimType.DateTime:
                    case CimType.Reference:
                        return val.ToString();

                    case CimType.Boolean:
                        return Convert.ToBoolean(val, (IFormatProvider) invariantCulture.GetFormat(typeof(bool)));

                    case CimType.Object:
                        if (val is ManagementBaseObject)
                        {
                            return Marshal.GetObjectForIUnknown((IntPtr) ((ManagementBaseObject) val).wbemObject);
                        }
                        return val;

                    case CimType.SInt8:
                        return (short) Convert.ToSByte(val, (IFormatProvider) invariantCulture.GetFormat(typeof(short)));

                    case CimType.UInt8:
                        return Convert.ToByte(val, (IFormatProvider) invariantCulture.GetFormat(typeof(byte)));

                    case CimType.UInt16:
                        return (int) Convert.ToUInt16(val, (IFormatProvider) invariantCulture.GetFormat(typeof(ushort)));

                    case CimType.UInt32:
                        return (int) Convert.ToUInt32(val, (IFormatProvider) invariantCulture.GetFormat(typeof(uint)));

                    case CimType.SInt64:
                        return Convert.ToInt64(val, (IFormatProvider) invariantCulture.GetFormat(typeof(long))).ToString((IFormatProvider) invariantCulture.GetFormat(typeof(long)));

                    case CimType.UInt64:
                        return Convert.ToUInt64(val, (IFormatProvider) invariantCulture.GetFormat(typeof(ulong))).ToString((IFormatProvider) invariantCulture.GetFormat(typeof(ulong)));

                    case CimType.Char16:
                        return (short) Convert.ToChar(val, (IFormatProvider) invariantCulture.GetFormat(typeof(char)));
                }
                return val;
            }
            Array array = (Array) val;
            int length = array.Length;
            switch (type)
            {
                case CimType.SInt16:
                    if (val is short[])
                    {
                        return val;
                    }
                    obj2 = new short[length];
                    for (int i = 0; i < length; i++)
                    {
                        ((short[]) obj2)[i] = Convert.ToInt16(array.GetValue(i), (IFormatProvider) invariantCulture.GetFormat(typeof(short)));
                    }
                    return obj2;

                case CimType.SInt32:
                    if (val is int[])
                    {
                        return val;
                    }
                    obj2 = new int[length];
                    for (int j = 0; j < length; j++)
                    {
                        ((int[]) obj2)[j] = Convert.ToInt32(array.GetValue(j), (IFormatProvider) invariantCulture.GetFormat(typeof(int)));
                    }
                    return obj2;

                case CimType.Real32:
                    if (val is float[])
                    {
                        return val;
                    }
                    obj2 = new float[length];
                    for (int k = 0; k < length; k++)
                    {
                        ((float[]) obj2)[k] = Convert.ToSingle(array.GetValue(k), (IFormatProvider) invariantCulture.GetFormat(typeof(float)));
                    }
                    return obj2;

                case CimType.Real64:
                    if (val is double[])
                    {
                        return val;
                    }
                    obj2 = new double[length];
                    for (int m = 0; m < length; m++)
                    {
                        ((double[]) obj2)[m] = Convert.ToDouble(array.GetValue(m), (IFormatProvider) invariantCulture.GetFormat(typeof(double)));
                    }
                    return obj2;

                case (CimType.Real32 | CimType.SInt16):
                case (CimType.Real64 | CimType.SInt16):
                case ((CimType) 9):
                case (CimType.String | CimType.SInt16):
                case (CimType.String | CimType.Real32):
                case (CimType.String | CimType.Real32 | CimType.SInt16):
                case (CimType.Object | CimType.SInt16):
                    return val;

                case CimType.String:
                case CimType.DateTime:
                case CimType.Reference:
                    if (val is string[])
                    {
                        return val;
                    }
                    obj2 = new string[length];
                    for (int n = 0; n < length; n++)
                    {
                        ((string[]) obj2)[n] = array.GetValue(n).ToString();
                    }
                    return obj2;

                case CimType.Boolean:
                    if (val is bool[])
                    {
                        return val;
                    }
                    obj2 = new bool[length];
                    for (int num14 = 0; num14 < length; num14++)
                    {
                        ((bool[]) obj2)[num14] = Convert.ToBoolean(array.GetValue(num14), (IFormatProvider) invariantCulture.GetFormat(typeof(bool)));
                    }
                    return obj2;

                case CimType.Object:
                    obj2 = new IWbemClassObject_DoNotMarshal[length];
                    for (int num15 = 0; num15 < length; num15++)
                    {
                        ((IWbemClassObject_DoNotMarshal[]) obj2)[num15] = (IWbemClassObject_DoNotMarshal) Marshal.GetObjectForIUnknown((IntPtr) ((ManagementBaseObject) array.GetValue(num15)).wbemObject);
                    }
                    return obj2;

                case CimType.SInt8:
                    obj2 = new short[length];
                    for (int num2 = 0; num2 < length; num2++)
                    {
                        ((short[]) obj2)[num2] = Convert.ToSByte(array.GetValue(num2), (IFormatProvider) invariantCulture.GetFormat(typeof(sbyte)));
                    }
                    return obj2;

                case CimType.UInt8:
                    if (val is byte[])
                    {
                        return val;
                    }
                    obj2 = new byte[length];
                    for (int num3 = 0; num3 < length; num3++)
                    {
                        ((byte[]) obj2)[num3] = Convert.ToByte(array.GetValue(num3), (IFormatProvider) invariantCulture.GetFormat(typeof(byte)));
                    }
                    return obj2;

                case CimType.UInt16:
                    obj2 = new int[length];
                    for (int num5 = 0; num5 < length; num5++)
                    {
                        ((int[]) obj2)[num5] = Convert.ToUInt16(array.GetValue(num5), (IFormatProvider) invariantCulture.GetFormat(typeof(ushort)));
                    }
                    return obj2;

                case CimType.UInt32:
                    obj2 = new int[length];
                    for (int num7 = 0; num7 < length; num7++)
                    {
                        ((int[]) obj2)[num7] = (int) Convert.ToUInt32(array.GetValue(num7), (IFormatProvider) invariantCulture.GetFormat(typeof(uint)));
                    }
                    return obj2;

                case CimType.SInt64:
                    obj2 = new string[length];
                    for (int num8 = 0; num8 < length; num8++)
                    {
                        ((string[]) obj2)[num8] = Convert.ToInt64(array.GetValue(num8), (IFormatProvider) invariantCulture.GetFormat(typeof(long))).ToString((IFormatProvider) invariantCulture.GetFormat(typeof(long)));
                    }
                    return obj2;

                case CimType.UInt64:
                    obj2 = new string[length];
                    for (int num9 = 0; num9 < length; num9++)
                    {
                        ((string[]) obj2)[num9] = Convert.ToUInt64(array.GetValue(num9), (IFormatProvider) invariantCulture.GetFormat(typeof(ulong))).ToString((IFormatProvider) invariantCulture.GetFormat(typeof(ulong)));
                    }
                    return obj2;

                case CimType.Char16:
                    obj2 = new short[length];
                    for (int num12 = 0; num12 < length; num12++)
                    {
                        ((short[]) obj2)[num12] = (short) Convert.ToChar(array.GetValue(num12), (IFormatProvider) invariantCulture.GetFormat(typeof(char)));
                    }
                    return obj2;
            }
            return val;
        }
예제 #43
0
		int System.Management.IWbemServices_Old.GetObject_(string strObjectPath, int lFlags, IWbemContext pCtx, out IWbemClassObject_DoNotMarshal ppObject, IntPtr ppCallResult)
		{
			ppObject = null;
			return -2147217396;
		}
예제 #44
0
		internal static object MapValueToWmiValue(object val, out bool isArray, out CimType type)
		{
			object value = DBNull.Value;
			CultureInfo invariantCulture = CultureInfo.InvariantCulture;
			isArray = false;
			type = CimType.None;
			if (val != null)
			{
				isArray = val.GetType().IsArray;
				Type type1 = val.GetType();
				if (!isArray)
				{
					if (type1 != typeof(ushort))
					{
						if (type1 != typeof(uint))
						{
							if (type1 != typeof(ulong))
							{
								if (type1 != typeof(sbyte))
								{
									if (type1 != typeof(byte))
									{
										if (type1 != typeof(short))
										{
											if (type1 != typeof(int))
											{
												if (type1 != typeof(long))
												{
													if (type1 != typeof(bool))
													{
														if (type1 != typeof(float))
														{
															if (type1 != typeof(double))
															{
																if (type1 != typeof(char))
																{
																	if (type1 != typeof(string))
																	{
																		if (val as ManagementBaseObject != null)
																		{
																			type = CimType.Object;
																			value = Marshal.GetObjectForIUnknown(((ManagementBaseObject)val).wbemObject);
																		}
																	}
																	else
																	{
																		type = CimType.String;
																		value = val;
																	}
																}
																else
																{
																	type = CimType.Char16;
																	value = ((IConvertible)(char)val).ToInt16(null);
																}
															}
															else
															{
																type = CimType.Real64;
																value = val;
															}
														}
														else
														{
															type = CimType.Real32;
															value = val;
														}
													}
													else
													{
														type = CimType.Boolean;
														value = val;
													}
												}
												else
												{
													type = CimType.SInt64;
													value = val.ToString();
												}
											}
											else
											{
												type = CimType.SInt32;
												value = val;
											}
										}
										else
										{
											type = CimType.SInt16;
											value = val;
										}
									}
									else
									{
										type = CimType.UInt8;
										value = val;
									}
								}
								else
								{
									type = CimType.SInt8;
									value = ((IConvertible)(sbyte)val).ToInt16(null);
								}
							}
							else
							{
								type = CimType.UInt64;
								ulong num = (ulong)val;
								value = num.ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
							}
						}
						else
						{
							type = CimType.UInt32;
							if (((uint)val & -2147483648) == 0)
							{
								value = Convert.ToInt32(val, (IFormatProvider)invariantCulture.GetFormat(typeof(int)));
							}
							else
							{
								value = Convert.ToString(val, (IFormatProvider)invariantCulture.GetFormat(typeof(uint)));
							}
						}
					}
					else
					{
						type = CimType.UInt16;
						value = ((IConvertible)(ushort)val).ToInt32(null);
					}
				}
				else
				{
					Type elementType = type1.GetElementType();
					if (!elementType.IsPrimitive)
					{
						if (elementType != typeof(string))
						{
							if (val as ManagementBaseObject[] != null)
							{
								Array arrays = (Array)val;
								int length = arrays.Length;
								type = CimType.Object;
								value = new IWbemClassObject_DoNotMarshal[length];
								for (int i = 0; i < length; i++)
								{
									((IWbemClassObject_DoNotMarshal[])value)[i] = (IWbemClassObject_DoNotMarshal)Marshal.GetObjectForIUnknown(((ManagementBaseObject)arrays.GetValue(i)).wbemObject);
								}
							}
						}
						else
						{
							type = CimType.String;
							value = (string[])val;
						}
					}
					else
					{
						if (elementType != typeof(byte))
						{
							if (elementType != typeof(sbyte))
							{
								if (elementType != typeof(bool))
								{
									if (elementType != typeof(ushort))
									{
										if (elementType != typeof(short))
										{
											if (elementType != typeof(int))
											{
												if (elementType != typeof(uint))
												{
													if (elementType != typeof(ulong))
													{
														if (elementType != typeof(long))
														{
															if (elementType != typeof(float))
															{
																if (elementType != typeof(double))
																{
																	if (elementType == typeof(char))
																	{
																		char[] chrArray = (char[])val;
																		int length1 = (int)chrArray.Length;
																		type = CimType.Char16;
																		value = new short[length1];
																		for (int j = 0; j < length1; j++)
																		{
																			((short[])value)[j] = ((IConvertible)chrArray[j]).ToInt16(null);
																		}
																	}
																}
																else
																{
																	type = CimType.Real64;
																	value = (double[])val;
																}
															}
															else
															{
																type = CimType.Real32;
																value = (float[])val;
															}
														}
														else
														{
															long[] numArray = (long[])val;
															int num1 = (int)numArray.Length;
															type = CimType.SInt64;
															value = new string[num1];
															for (int k = 0; k < num1; k++)
															{
																((string[])value)[k] = numArray[k].ToString((IFormatProvider)invariantCulture.GetFormat(typeof(long)));
															}
														}
													}
													else
													{
														ulong[] numArray1 = (ulong[])val;
														int length2 = (int)numArray1.Length;
														type = CimType.UInt64;
														value = new string[length2];
														for (int l = 0; l < length2; l++)
														{
															((string[])value)[l] = numArray1[l].ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
														}
													}
												}
												else
												{
													uint[] numArray2 = (uint[])val;
													int num2 = (int)numArray2.Length;
													type = CimType.UInt32;
													value = new string[num2];
													for (int m = 0; m < num2; m++)
													{
														((string[])value)[m] = numArray2[m].ToString((IFormatProvider)invariantCulture.GetFormat(typeof(uint)));
													}
												}
											}
											else
											{
												type = CimType.SInt32;
												value = (int[])val;
											}
										}
										else
										{
											type = CimType.SInt16;
											value = (short[])val;
										}
									}
									else
									{
										ushort[] numArray3 = (ushort[])val;
										int length3 = (int)numArray3.Length;
										type = CimType.UInt16;
										value = new int[length3];
										for (int n = 0; n < length3; n++)
										{
											((int[])value)[n] = ((IConvertible)numArray3[n]).ToInt32(null);
										}
									}
								}
								else
								{
									type = CimType.Boolean;
									value = (bool[])val;
								}
							}
							else
							{
								sbyte[] numArray4 = (sbyte[])val;
								int num3 = (int)numArray4.Length;
								type = CimType.SInt8;
								value = new short[num3];
								for (int o = 0; o < num3; o++)
								{
									((short[])value)[o] = ((IConvertible)numArray4[o]).ToInt16(null);
								}
							}
						}
						else
						{
							byte[] numArray5 = (byte[])val;
							int length4 = (int)numArray5.Length;
							type = CimType.UInt8;
							value = new short[length4];
							for (int p = 0; p < length4; p++)
							{
								((short[])value)[p] = ((IConvertible)numArray5[p]).ToInt16(null);
							}
						}
					}
				}
			}
			return value;
		}
예제 #45
0
        /// <summary>
        /// Takes a managed code value, together with a desired property
        /// </summary>
        /// <param name="val"> </param>
        /// <param name="type"> </param>
        /// <param name="isArray"> </param>
        internal static object MapValueToWmiValue(object val, CimType type, bool isArray)
        {
            object      wmiValue = System.DBNull.Value;
            CultureInfo culInfo  = CultureInfo.InvariantCulture;

            if (null != val)
            {
                if (isArray)
                {
                    Array valArray = (Array)val;
                    int   length   = valArray.Length;

                    switch (type)
                    {
                    case CimType.SInt8:
                        wmiValue = new Int16 [length];
                        for (int i = 0; i < length; i++)
                        {
                            ((Int16[])(wmiValue))[i] = (Int16)Convert.ToSByte(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.SByte)));
                        }
                        break;

                    case CimType.UInt8:
                        if (val is Byte[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new Byte [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((Byte[])wmiValue)[i] = Convert.ToByte(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Byte)));
                            }
                        }
                        break;

                    case CimType.SInt16:
                        if (val is Int16[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new Int16 [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((Int16[])(wmiValue))[i] = Convert.ToInt16(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Int16)));
                            }
                        }
                        break;

                    case CimType.UInt16:
                        wmiValue = new Int32 [length];
                        for (int i = 0; i < length; i++)
                        {
                            ((Int32[])(wmiValue))[i] = (Int32)(Convert.ToUInt16(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.UInt16))));
                        }
                        break;

                    case CimType.SInt32:
                        if (val is Int32[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new Int32 [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((Int32[])(wmiValue))[i] = Convert.ToInt32(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Int32)));
                            }
                        }
                        break;

                    case CimType.UInt32:
                        wmiValue = new Int32 [length];
                        for (int i = 0; i < length; i++)
                        {
                            ((Int32[])(wmiValue))[i] = (Int32)(Convert.ToUInt32(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.UInt32))));
                        }
                        break;

                    case CimType.SInt64:
                        wmiValue = new String [length];
                        for (int i = 0; i < length; i++)
                        {
                            ((String[])(wmiValue))[i] = (Convert.ToInt64(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Int64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.Int64)));
                        }
                        break;

                    case CimType.UInt64:
                        wmiValue = new String [length];
                        for (int i = 0; i < length; i++)
                        {
                            ((String[])(wmiValue))[i] = (Convert.ToUInt64(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)));
                        }
                        break;

                    case CimType.Real32:
                        if (val is Single[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new Single [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((Single[])(wmiValue))[i] = Convert.ToSingle(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Single)));
                            }
                        }
                        break;

                    case CimType.Real64:
                        if (val is Double[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new Double [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((Double[])(wmiValue))[i] = Convert.ToDouble(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Double)));
                            }
                        }
                        break;

                    case CimType.Char16:
                        wmiValue = new Int16 [length];
                        for (int i = 0; i < length; i++)
                        {
                            ((Int16[])(wmiValue))[i] = (Int16)Convert.ToChar(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Char)));
                        }
                        break;

                    case CimType.String:
                    case CimType.DateTime:
                    case CimType.Reference:
                        if (val is String[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new String [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((String[])(wmiValue))[i] = (valArray.GetValue(i)).ToString();
                            }
                        }
                        break;

                    case CimType.Boolean:
                        if (val is Boolean[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new Boolean [length];
                            for (int i = 0; i < length; i++)
                            {
                                ((Boolean[])(wmiValue))[i] = Convert.ToBoolean(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(System.Boolean)));
                            }
                        }
                        break;

                    case CimType.Object:
                        wmiValue = new IWbemClassObject_DoNotMarshal[length];

                        for (int i = 0; i < length; i++)
                        {
                            //
                            // Removed below Initialize call since wbemObject is a property that will call Initialize ( true ) on
                            // its getter.
                            //
                            //((ManagementBaseObject)valArray.GetValue(i)).Initialize ( false ) ;
                            ((IWbemClassObject_DoNotMarshal[])(wmiValue))[i] = (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(((ManagementBaseObject)valArray.GetValue(i)).wbemObject));
                        }
                        break;

                    default:
                        wmiValue = val;
                        break;
                    }
                }
                else
                {
                    switch (type)
                    {
                    case CimType.SInt8:
                        wmiValue = (Int16)Convert.ToSByte(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Int16)));
                        break;

                    case CimType.UInt8:
                        wmiValue = Convert.ToByte(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Byte)));
                        break;

                    case CimType.SInt16:
                        wmiValue = Convert.ToInt16(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Int16)));
                        break;

                    case CimType.UInt16:
                        wmiValue = (Int32)(Convert.ToUInt16(val, (IFormatProvider)culInfo.GetFormat(typeof(System.UInt16))));
                        break;

                    case CimType.SInt32:
                        wmiValue = Convert.ToInt32(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Int32)));
                        break;

                    case CimType.UInt32:
                        wmiValue = (Int32)Convert.ToUInt32(val, (IFormatProvider)culInfo.GetFormat(typeof(System.UInt32)));
                        break;

                    case CimType.SInt64:
                        wmiValue = (Convert.ToInt64(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Int64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.Int64)));
                        break;

                    case CimType.UInt64:
                        wmiValue = (Convert.ToUInt64(val, (IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(System.UInt64)));
                        break;

                    case CimType.Real32:
                        wmiValue = Convert.ToSingle(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Single)));
                        break;

                    case CimType.Real64:
                        wmiValue = Convert.ToDouble(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Double)));
                        break;

                    case CimType.Char16:
                        wmiValue = (Int16)Convert.ToChar(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Char)));
                        break;

                    case CimType.String:
                    case CimType.DateTime:
                    case CimType.Reference:
                        wmiValue = val.ToString();
                        break;

                    case CimType.Boolean:
                        wmiValue = Convert.ToBoolean(val, (IFormatProvider)culInfo.GetFormat(typeof(System.Boolean)));
                        break;

                    case CimType.Object:
                        if (val is ManagementBaseObject)
                        {
                            //
                            // Removed Initialize call since wbemObject is a property that will call Initialize ( true ) on
                            // its getter.
                            //
                            //((ManagementBaseObject)val).Initialize ( false ) ;
                            wmiValue = Marshal.GetObjectForIUnknown(((ManagementBaseObject)val).wbemObject);
                        }
                        else
                        {
                            //Debug.Assert(false, "Unhandled object type");
                            wmiValue = val;
                        }
                        break;

                    default:
                        wmiValue = val;
                        break;
                    }
                }
            }

            return(wmiValue);
        }
예제 #46
0
		public virtual int Clone_ (out IWbemClassObject_DoNotMarshal ppCopy)
		{
			ppCopy = this;
			return 0;
		}
예제 #47
0
파일: Property.cs 프로젝트: pgovind/runtime
        /// <summary>
        /// Takes a managed code value, together with a desired property
        /// </summary>
        /// <param name="val"> </param>
        /// <param name="type"> </param>
        /// <param name="isArray"> </param>
        internal static object MapValueToWmiValue(object val, CimType type, bool isArray)
        {
            object      wmiValue = System.DBNull.Value;
            CultureInfo culInfo  = CultureInfo.InvariantCulture;

            if (null != val)
            {
                if (isArray)
                {
                    Array valArray = (Array)val;
                    int   length   = valArray.Length;

                    switch (type)
                    {
                    case CimType.SInt8:
                        wmiValue = new short[length];
                        for (int i = 0; i < length; i++)
                        {
                            ((short[])(wmiValue))[i] = (short)Convert.ToSByte(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(sbyte)));
                        }
                        break;

                    case CimType.UInt8:
                        if (val is byte[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new byte[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((byte[])wmiValue)[i] = Convert.ToByte(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(byte)));
                            }
                        }
                        break;

                    case CimType.SInt16:
                        if (val is short[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new short[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((short[])(wmiValue))[i] = Convert.ToInt16(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(short)));
                            }
                        }
                        break;

                    case CimType.UInt16:
                        wmiValue = new int[length];
                        for (int i = 0; i < length; i++)
                        {
                            ((int[])(wmiValue))[i] = (int)(Convert.ToUInt16(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(ushort))));
                        }
                        break;

                    case CimType.SInt32:
                        if (val is int[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new int[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((int[])(wmiValue))[i] = Convert.ToInt32(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(int)));
                            }
                        }
                        break;

                    case CimType.UInt32:
                        wmiValue = new int[length];
                        for (int i = 0; i < length; i++)
                        {
                            ((int[])(wmiValue))[i] = (int)(Convert.ToUInt32(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(uint))));
                        }
                        break;

                    case CimType.SInt64:
                        wmiValue = new string[length];
                        for (int i = 0; i < length; i++)
                        {
                            ((string[])(wmiValue))[i] = (Convert.ToInt64(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(long)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(long)));
                        }
                        break;

                    case CimType.UInt64:
                        wmiValue = new string[length];
                        for (int i = 0; i < length; i++)
                        {
                            ((string[])(wmiValue))[i] = (Convert.ToUInt64(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(ulong)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(ulong)));
                        }
                        break;

                    case CimType.Real32:
                        if (val is float[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new float[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((float[])(wmiValue))[i] = Convert.ToSingle(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(float)));
                            }
                        }
                        break;

                    case CimType.Real64:
                        if (val is double[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new double[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((double[])(wmiValue))[i] = Convert.ToDouble(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(double)));
                            }
                        }
                        break;

                    case CimType.Char16:
                        wmiValue = new short[length];
                        for (int i = 0; i < length; i++)
                        {
                            ((short[])(wmiValue))[i] = (short)Convert.ToChar(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(char)));
                        }
                        break;

                    case CimType.String:
                    case CimType.DateTime:
                    case CimType.Reference:
                        if (val is string[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new string[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((string[])(wmiValue))[i] = (valArray.GetValue(i)).ToString();
                            }
                        }
                        break;

                    case CimType.Boolean:
                        if (val is bool[])
                        {
                            wmiValue = val;
                        }
                        else
                        {
                            wmiValue = new bool[length];
                            for (int i = 0; i < length; i++)
                            {
                                ((bool[])(wmiValue))[i] = Convert.ToBoolean(valArray.GetValue(i), (IFormatProvider)culInfo.GetFormat(typeof(bool)));
                            }
                        }
                        break;

                    case CimType.Object:
                        wmiValue = new IWbemClassObject_DoNotMarshal[length];

                        for (int i = 0; i < length; i++)
                        {
                            ((IWbemClassObject_DoNotMarshal[])(wmiValue))[i] = (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(((ManagementBaseObject)valArray.GetValue(i)).wbemObject));
                        }
                        break;

                    default:
                        wmiValue = val;
                        break;
                    }
                }
                else
                {
                    switch (type)
                    {
                    case CimType.SInt8:
                        wmiValue = (short)Convert.ToSByte(val, (IFormatProvider)culInfo.GetFormat(typeof(short)));
                        break;

                    case CimType.UInt8:
                        wmiValue = Convert.ToByte(val, (IFormatProvider)culInfo.GetFormat(typeof(byte)));
                        break;

                    case CimType.SInt16:
                        wmiValue = Convert.ToInt16(val, (IFormatProvider)culInfo.GetFormat(typeof(short)));
                        break;

                    case CimType.UInt16:
                        wmiValue = (int)(Convert.ToUInt16(val, (IFormatProvider)culInfo.GetFormat(typeof(ushort))));
                        break;

                    case CimType.SInt32:
                        wmiValue = Convert.ToInt32(val, (IFormatProvider)culInfo.GetFormat(typeof(int)));
                        break;

                    case CimType.UInt32:
                        wmiValue = (int)Convert.ToUInt32(val, (IFormatProvider)culInfo.GetFormat(typeof(uint)));
                        break;

                    case CimType.SInt64:
                        wmiValue = (Convert.ToInt64(val, (IFormatProvider)culInfo.GetFormat(typeof(long)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(long)));
                        break;

                    case CimType.UInt64:
                        wmiValue = (Convert.ToUInt64(val, (IFormatProvider)culInfo.GetFormat(typeof(ulong)))).ToString((IFormatProvider)culInfo.GetFormat(typeof(ulong)));
                        break;

                    case CimType.Real32:
                        wmiValue = Convert.ToSingle(val, (IFormatProvider)culInfo.GetFormat(typeof(float)));
                        break;

                    case CimType.Real64:
                        wmiValue = Convert.ToDouble(val, (IFormatProvider)culInfo.GetFormat(typeof(double)));
                        break;

                    case CimType.Char16:
                        wmiValue = (short)Convert.ToChar(val, (IFormatProvider)culInfo.GetFormat(typeof(char)));
                        break;

                    case CimType.String:
                    case CimType.DateTime:
                    case CimType.Reference:
                        wmiValue = val.ToString();
                        break;

                    case CimType.Boolean:
                        wmiValue = Convert.ToBoolean(val, (IFormatProvider)culInfo.GetFormat(typeof(bool)));
                        break;

                    case CimType.Object:
                        if (val is ManagementBaseObject)
                        {
                            wmiValue = Marshal.GetObjectForIUnknown(((ManagementBaseObject)val).wbemObject);
                        }
                        else
                        {
                            wmiValue = val;
                        }
                        break;

                    default:
                        wmiValue = val;
                        break;
                    }
                }
            }

            return(wmiValue);
        }
예제 #48
0
		public virtual int CompareTo_ (int lFlags, IWbemClassObject_DoNotMarshal pCompareTo)
		{
			throw new NotImplementedException ();
		}
예제 #49
0
 int IWbemServices_Old.ExecMethodAsync_([In, MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In, MarshalAs(UnmanagedType.BStr)] string strMethodName, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In, MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pInParams, [In, MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler)
 {
     return(-2147217396);
 }
예제 #50
0
        /// <summary>
        ///    <para>Waits for the next event that matches the specified query to arrive, and
        ///       then returns it.</para>
        /// </summary>
        /// <returns>
        /// <para>A <see cref='System.Management.ManagementBaseObject'/> representing the
        ///    newly arrived event.</para>
        /// </returns>
        /// <remarks>
        ///    <para>If the event watcher object contains options with
        ///       a specified timeout, the API will wait for the next event only for the specified
        ///       amount of time; otherwise, the API will be blocked until the next event occurs.</para>
        /// </remarks>
        public ManagementBaseObject WaitForNextEvent()
        {
            ManagementBaseObject obj = null;

            Initialize();

#pragma warning disable CA2002
            lock (this)
#pragma warning restore CA2002
            {
                SecurityHandler securityHandler = Scope.GetSecurityHandler();

                int status = (int)ManagementStatus.NoError;

                try
                {
                    if (null == enumWbem)   //don't have an enumerator yet - get it
                    {
                        //Execute the query
                        status = scope.GetSecuredIWbemServicesHandler(Scope.GetIWbemServices()).ExecNotificationQuery_(
                            query.QueryLanguage,
                            query.QueryString,
                            options.Flags,
                            options.GetContext(),
                            ref enumWbem);
                    }

                    if (status >= 0)
                    {
                        if ((cachedCount - cacheIndex) == 0) //cache is empty - need to get more objects
                        {
                            //Because Interop doesn't support custom marshalling for arrays, we have to use
                            //the "DoNotMarshal" objects in the interop and then convert to the "FreeThreaded"
                            //counterparts afterwards.
                            IWbemClassObject_DoNotMarshal[] tempArray = new IWbemClassObject_DoNotMarshal[options.BlockSize];

                            int timeout = (ManagementOptions.InfiniteTimeout == options.Timeout)
                                ? (int)tag_WBEM_TIMEOUT_TYPE.WBEM_INFINITE :
                                          (int)options.Timeout.TotalMilliseconds;

                            status     = scope.GetSecuredIEnumWbemClassObjectHandler(enumWbem).Next_(timeout, (uint)options.BlockSize, tempArray, ref cachedCount);
                            cacheIndex = 0;

                            if (status >= 0)
                            {
                                //Convert results and put them in cache. Note that we may have timed out
                                //in which case we might not have all the objects. If no object can be returned
                                //we throw a timeout exception.
                                if (cachedCount == 0)
                                {
                                    ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);
                                }

                                for (int i = 0; i < cachedCount; i++)
                                {
                                    cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(tempArray[i]));
                                }
                            }
                        }

                        if (status >= 0)
                        {
                            obj = new ManagementBaseObject(cachedObjects[cacheIndex]);
                            cacheIndex++;
                        }
                    }
                }
                finally
                {
                    securityHandler.Reset();
                }

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

            return(obj);
        }
예제 #51
0
 int IWbemServices_Old.GetObject_([In, MarshalAs(UnmanagedType.BStr)] string strObjectPath, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In, Out, MarshalAs(UnmanagedType.Interface)] ref IWbemClassObject_DoNotMarshal ppObject, [In] IntPtr ppCallResult)
 {
     return(-2147217396);
 }
예제 #52
0
파일: Property.cs 프로젝트: pgovind/runtime
        internal static object MapValueToWmiValue(object val, out bool isArray, out CimType type)
        {
            object      wmiValue = System.DBNull.Value;
            CultureInfo culInfo  = CultureInfo.InvariantCulture;

            isArray = false;
            type    = 0;

            if (null != val)
            {
                isArray = val.GetType().IsArray;
                Type valueType = val.GetType();

                if (isArray)
                {
                    Type elementType = valueType.GetElementType();

                    // Casting primitive types to object[] is not allowed
                    if (elementType.IsPrimitive)
                    {
                        if (elementType == typeof(byte))
                        {
                            byte[] arrayValue = (byte[])val;
                            int    length     = arrayValue.Length;
                            type     = CimType.UInt8;
                            wmiValue = new short[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((short[])wmiValue)[i] = ((IConvertible)((byte)(arrayValue[i]))).ToInt16(null);
                            }
                        }
                        else if (elementType == typeof(sbyte))
                        {
                            sbyte[] arrayValue = (sbyte[])val;
                            int     length     = arrayValue.Length;
                            type     = CimType.SInt8;
                            wmiValue = new short[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((short[])wmiValue)[i] = ((IConvertible)((sbyte)(arrayValue[i]))).ToInt16(null);
                            }
                        }
                        else if (elementType == typeof(bool))
                        {
                            type     = CimType.Boolean;
                            wmiValue = (bool[])val;
                        }
                        else if (elementType == typeof(ushort))
                        {
                            ushort[] arrayValue = (ushort[])val;
                            int      length     = arrayValue.Length;
                            type     = CimType.UInt16;
                            wmiValue = new int[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((int[])wmiValue)[i] = ((IConvertible)((ushort)(arrayValue[i]))).ToInt32(null);
                            }
                        }
                        else if (elementType == typeof(short))
                        {
                            type     = CimType.SInt16;
                            wmiValue = (short[])val;
                        }
                        else if (elementType == typeof(int))
                        {
                            type     = CimType.SInt32;
                            wmiValue = (int[])val;
                        }
                        else if (elementType == typeof(uint))
                        {
                            uint[] arrayValue = (uint[])val;
                            int    length     = arrayValue.Length;
                            type     = CimType.UInt32;
                            wmiValue = new string[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((string[])wmiValue)[i] = ((uint)(arrayValue[i])).ToString((IFormatProvider)culInfo.GetFormat(typeof(uint)));
                            }
                        }
                        else if (elementType == typeof(ulong))
                        {
                            ulong[] arrayValue = (ulong[])val;
                            int     length     = arrayValue.Length;
                            type     = CimType.UInt64;
                            wmiValue = new string[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((string[])wmiValue)[i] = ((ulong)(arrayValue[i])).ToString((IFormatProvider)culInfo.GetFormat(typeof(ulong)));
                            }
                        }
                        else if (elementType == typeof(long))
                        {
                            long[] arrayValue = (long[])val;
                            int    length     = arrayValue.Length;
                            type     = CimType.SInt64;
                            wmiValue = new string[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((string[])wmiValue)[i] = ((long)(arrayValue[i])).ToString((IFormatProvider)culInfo.GetFormat(typeof(long)));
                            }
                        }
                        else if (elementType == typeof(float))
                        {
                            type     = CimType.Real32;
                            wmiValue = (float[])val;
                        }
                        else if (elementType == typeof(double))
                        {
                            type     = CimType.Real64;
                            wmiValue = (double[])val;
                        }
                        else if (elementType == typeof(char))
                        {
                            char[] arrayValue = (char[])val;
                            int    length     = arrayValue.Length;
                            type     = CimType.Char16;
                            wmiValue = new short[length];

                            for (int i = 0; i < length; i++)
                            {
                                ((short[])wmiValue)[i] = ((IConvertible)((char)(arrayValue[i]))).ToInt16(null);
                            }
                        }
                    }
                    else
                    {
                        // Non-primitive types
                        if (elementType == typeof(string))
                        {
                            type     = CimType.String;
                            wmiValue = (string[])val;
                        }
                        else
                        {
                            // Check for an embedded object array
                            if (val is ManagementBaseObject[])
                            {
                                Array valArray = (Array)val;
                                int   length   = valArray.Length;
                                type     = CimType.Object;
                                wmiValue = new IWbemClassObject_DoNotMarshal[length];

                                for (int i = 0; i < length; i++)
                                {
                                    ((IWbemClassObject_DoNotMarshal[])(wmiValue))[i] = (IWbemClassObject_DoNotMarshal)(Marshal.GetObjectForIUnknown(((ManagementBaseObject)valArray.GetValue(i)).wbemObject));
                                }
                            }
                        }
                    }
                }
                else    // Non-array values
                {
                    if (valueType == typeof(ushort))
                    {
                        type     = CimType.UInt16;
                        wmiValue = ((IConvertible)((ushort)val)).ToInt32(null);
                    }
                    else if (valueType == typeof(uint))
                    {
                        type = CimType.UInt32;
                        if (((uint)val & 0x80000000) != 0)
                        {
                            wmiValue = Convert.ToString(val, (IFormatProvider)culInfo.GetFormat(typeof(uint)));
                        }
                        else
                        {
                            wmiValue = Convert.ToInt32(val, (IFormatProvider)culInfo.GetFormat(typeof(int)));
                        }
                    }
                    else if (valueType == typeof(ulong))
                    {
                        type     = CimType.UInt64;
                        wmiValue = ((ulong)val).ToString((IFormatProvider)culInfo.GetFormat(typeof(ulong)));
                    }
                    else if (valueType == typeof(sbyte))
                    {
                        type     = CimType.SInt8;
                        wmiValue = ((IConvertible)((sbyte)val)).ToInt16(null);
                    }
                    else if (valueType == typeof(byte))
                    {
                        type     = CimType.UInt8;
                        wmiValue = val;
                    }
                    else if (valueType == typeof(short))
                    {
                        type     = CimType.SInt16;
                        wmiValue = val;
                    }
                    else if (valueType == typeof(int))
                    {
                        type     = CimType.SInt32;
                        wmiValue = val;
                    }
                    else if (valueType == typeof(long))
                    {
                        type     = CimType.SInt64;
                        wmiValue = val.ToString();
                    }
                    else if (valueType == typeof(bool))
                    {
                        type     = CimType.Boolean;
                        wmiValue = val;
                    }
                    else if (valueType == typeof(float))
                    {
                        type     = CimType.Real32;
                        wmiValue = val;
                    }
                    else if (valueType == typeof(double))
                    {
                        type     = CimType.Real64;
                        wmiValue = val;
                    }
                    else if (valueType == typeof(char))
                    {
                        type     = CimType.Char16;
                        wmiValue = ((IConvertible)((char)val)).ToInt16(null);
                    }
                    else if (valueType == typeof(string))
                    {
                        type     = CimType.String;
                        wmiValue = val;
                    }
                    else
                    {
                        // Check for an embedded object
                        if (val is ManagementBaseObject)
                        {
                            type     = CimType.Object;
                            wmiValue = Marshal.GetObjectForIUnknown(((ManagementBaseObject)val).wbemObject);
                        }
                    }
                }
            }

            return(wmiValue);
        }
예제 #53
0
 int IWbemServices_Old.PutInstance_([In, MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pInst, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In] IntPtr ppCallResult)
 {
     return(-2147217396);
 }
예제 #54
0
		int System.Management.IWbemServices_Old.ExecMethodAsync_(string strObjectPath, string strMethodName, int lFlags, IWbemContext pCtx, IWbemClassObject_DoNotMarshal pInParams, IWbemObjectSink pResponseHandler)
		{
			return -2147217396;
		}
예제 #55
0
 int IWbemServices_Old.PutInstanceAsync_([In, MarshalAs(UnmanagedType.Interface)] IWbemClassObject_DoNotMarshal pInst, [In] int lFlags, [In, MarshalAs(UnmanagedType.Interface)] IWbemContext pCtx, [In, MarshalAs(UnmanagedType.Interface)] IWbemObjectSink pResponseHandler)
 {
     return(-2147217396);
 }
예제 #56
0
		int System.Management.IWbemServices_Old.PutInstance_(IWbemClassObject_DoNotMarshal pInst, int lFlags, IWbemContext pCtx, IntPtr ppCallResult)
		{
			return -2147217396;
		}
        internal static object MapValueToWmiValue(object val, CimType type, bool isArray)
        {
            object      obj2             = DBNull.Value;
            CultureInfo invariantCulture = CultureInfo.InvariantCulture;

            if (val == null)
            {
                return(obj2);
            }
            if (!isArray)
            {
                switch (type)
                {
                case CimType.SInt16:
                    return(Convert.ToInt16(val, (IFormatProvider)invariantCulture.GetFormat(typeof(short))));

                case CimType.SInt32:
                    return(Convert.ToInt32(val, (IFormatProvider)invariantCulture.GetFormat(typeof(int))));

                case CimType.Real32:
                    return(Convert.ToSingle(val, (IFormatProvider)invariantCulture.GetFormat(typeof(float))));

                case CimType.Real64:
                    return(Convert.ToDouble(val, (IFormatProvider)invariantCulture.GetFormat(typeof(double))));

                case (CimType.Real32 | CimType.SInt16):
                case (CimType.Real64 | CimType.SInt16):
                case ((CimType)9):
                case (CimType.String | CimType.SInt16):
                case (CimType.String | CimType.Real32):
                case (CimType.String | CimType.Real32 | CimType.SInt16):
                case (CimType.Object | CimType.SInt16):
                    return(val);

                case CimType.String:
                case CimType.DateTime:
                case CimType.Reference:
                    return(val.ToString());

                case CimType.Boolean:
                    return(Convert.ToBoolean(val, (IFormatProvider)invariantCulture.GetFormat(typeof(bool))));

                case CimType.Object:
                    if (val is ManagementBaseObject)
                    {
                        return(Marshal.GetObjectForIUnknown((IntPtr)((ManagementBaseObject)val).wbemObject));
                    }
                    return(val);

                case CimType.SInt8:
                    return((short)Convert.ToSByte(val, (IFormatProvider)invariantCulture.GetFormat(typeof(short))));

                case CimType.UInt8:
                    return(Convert.ToByte(val, (IFormatProvider)invariantCulture.GetFormat(typeof(byte))));

                case CimType.UInt16:
                    return((int)Convert.ToUInt16(val, (IFormatProvider)invariantCulture.GetFormat(typeof(ushort))));

                case CimType.UInt32:
                    return((int)Convert.ToUInt32(val, (IFormatProvider)invariantCulture.GetFormat(typeof(uint))));

                case CimType.SInt64:
                    return(Convert.ToInt64(val, (IFormatProvider)invariantCulture.GetFormat(typeof(long))).ToString((IFormatProvider)invariantCulture.GetFormat(typeof(long))));

                case CimType.UInt64:
                    return(Convert.ToUInt64(val, (IFormatProvider)invariantCulture.GetFormat(typeof(ulong))).ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong))));

                case CimType.Char16:
                    return((short)Convert.ToChar(val, (IFormatProvider)invariantCulture.GetFormat(typeof(char))));
                }
                return(val);
            }
            Array array  = (Array)val;
            int   length = array.Length;

            switch (type)
            {
            case CimType.SInt16:
                if (val is short[])
                {
                    return(val);
                }
                obj2 = new short[length];
                for (int i = 0; i < length; i++)
                {
                    ((short[])obj2)[i] = Convert.ToInt16(array.GetValue(i), (IFormatProvider)invariantCulture.GetFormat(typeof(short)));
                }
                return(obj2);

            case CimType.SInt32:
                if (val is int[])
                {
                    return(val);
                }
                obj2 = new int[length];
                for (int j = 0; j < length; j++)
                {
                    ((int[])obj2)[j] = Convert.ToInt32(array.GetValue(j), (IFormatProvider)invariantCulture.GetFormat(typeof(int)));
                }
                return(obj2);

            case CimType.Real32:
                if (val is float[])
                {
                    return(val);
                }
                obj2 = new float[length];
                for (int k = 0; k < length; k++)
                {
                    ((float[])obj2)[k] = Convert.ToSingle(array.GetValue(k), (IFormatProvider)invariantCulture.GetFormat(typeof(float)));
                }
                return(obj2);

            case CimType.Real64:
                if (val is double[])
                {
                    return(val);
                }
                obj2 = new double[length];
                for (int m = 0; m < length; m++)
                {
                    ((double[])obj2)[m] = Convert.ToDouble(array.GetValue(m), (IFormatProvider)invariantCulture.GetFormat(typeof(double)));
                }
                return(obj2);

            case (CimType.Real32 | CimType.SInt16):
            case (CimType.Real64 | CimType.SInt16):
            case ((CimType)9):
            case (CimType.String | CimType.SInt16):
            case (CimType.String | CimType.Real32):
            case (CimType.String | CimType.Real32 | CimType.SInt16):
            case (CimType.Object | CimType.SInt16):
                return(val);

            case CimType.String:
            case CimType.DateTime:
            case CimType.Reference:
                if (val is string[])
                {
                    return(val);
                }
                obj2 = new string[length];
                for (int n = 0; n < length; n++)
                {
                    ((string[])obj2)[n] = array.GetValue(n).ToString();
                }
                return(obj2);

            case CimType.Boolean:
                if (val is bool[])
                {
                    return(val);
                }
                obj2 = new bool[length];
                for (int num14 = 0; num14 < length; num14++)
                {
                    ((bool[])obj2)[num14] = Convert.ToBoolean(array.GetValue(num14), (IFormatProvider)invariantCulture.GetFormat(typeof(bool)));
                }
                return(obj2);

            case CimType.Object:
                obj2 = new IWbemClassObject_DoNotMarshal[length];
                for (int num15 = 0; num15 < length; num15++)
                {
                    ((IWbemClassObject_DoNotMarshal[])obj2)[num15] = (IWbemClassObject_DoNotMarshal)Marshal.GetObjectForIUnknown((IntPtr)((ManagementBaseObject)array.GetValue(num15)).wbemObject);
                }
                return(obj2);

            case CimType.SInt8:
                obj2 = new short[length];
                for (int num2 = 0; num2 < length; num2++)
                {
                    ((short[])obj2)[num2] = Convert.ToSByte(array.GetValue(num2), (IFormatProvider)invariantCulture.GetFormat(typeof(sbyte)));
                }
                return(obj2);

            case CimType.UInt8:
                if (val is byte[])
                {
                    return(val);
                }
                obj2 = new byte[length];
                for (int num3 = 0; num3 < length; num3++)
                {
                    ((byte[])obj2)[num3] = Convert.ToByte(array.GetValue(num3), (IFormatProvider)invariantCulture.GetFormat(typeof(byte)));
                }
                return(obj2);

            case CimType.UInt16:
                obj2 = new int[length];
                for (int num5 = 0; num5 < length; num5++)
                {
                    ((int[])obj2)[num5] = Convert.ToUInt16(array.GetValue(num5), (IFormatProvider)invariantCulture.GetFormat(typeof(ushort)));
                }
                return(obj2);

            case CimType.UInt32:
                obj2 = new int[length];
                for (int num7 = 0; num7 < length; num7++)
                {
                    ((int[])obj2)[num7] = (int)Convert.ToUInt32(array.GetValue(num7), (IFormatProvider)invariantCulture.GetFormat(typeof(uint)));
                }
                return(obj2);

            case CimType.SInt64:
                obj2 = new string[length];
                for (int num8 = 0; num8 < length; num8++)
                {
                    ((string[])obj2)[num8] = Convert.ToInt64(array.GetValue(num8), (IFormatProvider)invariantCulture.GetFormat(typeof(long))).ToString((IFormatProvider)invariantCulture.GetFormat(typeof(long)));
                }
                return(obj2);

            case CimType.UInt64:
                obj2 = new string[length];
                for (int num9 = 0; num9 < length; num9++)
                {
                    ((string[])obj2)[num9] = Convert.ToUInt64(array.GetValue(num9), (IFormatProvider)invariantCulture.GetFormat(typeof(ulong))).ToString((IFormatProvider)invariantCulture.GetFormat(typeof(ulong)));
                }
                return(obj2);

            case CimType.Char16:
                obj2 = new short[length];
                for (int num12 = 0; num12 < length; num12++)
                {
                    ((short[])obj2)[num12] = (short)Convert.ToChar(array.GetValue(num12), (IFormatProvider)invariantCulture.GetFormat(typeof(char)));
                }
                return(obj2);
            }
            return(val);
        }
		internal int Next_(int lTimeout, int uCount, IWbemClassObject_DoNotMarshal[] ppOutParams, ref uint puReturned)
		{
			int num = this.pEnumWbemClassObjectsecurityHelper.Next_(lTimeout, uCount, ppOutParams, out puReturned);
			return num;
		}
예제 #59
0
		public ManagementBaseObject WaitForNextEvent()
		{
			unsafe
			{
				int totalMilliseconds;
				ManagementBaseObject managementBaseObject = null;
				this.Initialize();
				lock (this)
				{
					SecurityHandler securityHandler = this.Scope.GetSecurityHandler();
					int num = 0;
					try
					{
						if (this.enumWbem == null)
						{
							num = this.scope.GetSecuredIWbemServicesHandler(this.Scope.GetIWbemServices()).ExecNotificationQuery_(this.query.QueryLanguage, this.query.QueryString, this.options.Flags, this.options.GetContext(), ref this.enumWbem);
						}
						if (num >= 0)
						{
							if (this.cachedCount - this.cacheIndex == 0)
							{
								IWbemClassObject_DoNotMarshal[] wbemClassObjectDoNotMarshalArray = new IWbemClassObject_DoNotMarshal[this.options.BlockSize];
								if (ManagementOptions.InfiniteTimeout == this.options.Timeout)
								{
									totalMilliseconds = -1;
								}
								else
								{
									TimeSpan timeout = this.options.Timeout;
									totalMilliseconds = (int)timeout.TotalMilliseconds;
								}
								int num1 = totalMilliseconds;
								num = this.scope.GetSecuredIEnumWbemClassObjectHandler(this.enumWbem).Next_(num1, this.options.BlockSize, wbemClassObjectDoNotMarshalArray, ref this.cachedCount);
								this.cacheIndex = 0;
								if (num >= 0)
								{
									if (this.cachedCount == 0)
									{
										ManagementException.ThrowWithExtendedInfo(ManagementStatus.Timedout);
									}
									for (int i = 0; (long)i < (long)this.cachedCount; i++)
									{
										this.cachedObjects[i] = new IWbemClassObjectFreeThreaded(Marshal.GetIUnknownForObject(wbemClassObjectDoNotMarshalArray[i].NativeObject));
									}
								}
							}
							if (num >= 0)
							{
								ManagementEventWatcher managementEventWatcher = this;
								managementEventWatcher.cacheIndex = managementEventWatcher.cacheIndex + 1;
							}
						}
					}
					finally
					{
						securityHandler.Reset();
					}
					if (num < 0)
					{
						if (((long)num & (long)-4096) != (long)-2147217408)
						{
							Marshal.ThrowExceptionForHR(num);
						}
						else
						{
							ManagementException.ThrowWithExtendedInfo((ManagementStatus)num);
						}
					}
				}
				return managementBaseObject;
			}
		}