示例#1
0
        public virtual object InvokeMethodByWmiPath(WmiInvokeMethodInfo wmiInvokeMethodInfo)
        {
            ManagementPath   mngPath      = this.getManagementPath(wmiInvokeMethodInfo.ClassName, wmiInvokeMethodInfo.PathName, wmiInvokeMethodInfo.PathValue);
            ManagementObject mngObject    = new ManagementObject(this._connectionScope, mngPath, null);
            object           methodReturn = null;

            try
            {
                methodReturn = mngObject.InvokeMethod(wmiInvokeMethodInfo.MethodName, null, null);
                if (methodReturn == null)
                {
                    throw new InvalidInvokeMethodException(mngPath.RelativePath, wmiInvokeMethodInfo.MethodName);
                }
            }
            catch (ManagementException)
            {
                throw new InvalidInvokeMethodException(mngPath.RelativePath, wmiInvokeMethodInfo.MethodName);
            }



            if (wmiInvokeMethodInfo.ShouldBeReturnManagementObjects())
            {
                return(methodReturn);
            }


            ManagementBaseObject systemObject  = (ManagementBaseObject)methodReturn;
            string fullObjectParentName        = wmiInvokeMethodInfo.OutParameters.ParentObjectNames.First();
            ManagementBaseObject currentObject = (ManagementBaseObject)systemObject.Properties[fullObjectParentName].Value;

            for (int i = 1; i < wmiInvokeMethodInfo.OutParameters.ParentObjectNames.Count; i++)
            {
                string currentObjectName = wmiInvokeMethodInfo.OutParameters.ParentObjectNames.ElementAt(i);
                object currentProperty   = currentObject.Properties[currentObjectName].Value;
                bool   IsCurrObjList     = (currentProperty is IEnumerable <ManagementBaseObject>);

                currentObject        = IsCurrObjList ? this.getNewCurrentObjByFilter(currentProperty, wmiInvokeMethodInfo.Filter) : (ManagementBaseObject)currentProperty;
                fullObjectParentName = fullObjectParentName + "." + currentObjectName;
            }

            if (currentObject == null)
            {
                throw new InvalidInvokeMethodFilterException(mngPath.RelativePath, wmiInvokeMethodInfo.MethodName);
            }

            IList <String> propertyNames = wmiInvokeMethodInfo.OutParameters.PropertyNames;
            var            newWmiObject  = this.createWmiObjectWithProperties(currentObject, fullObjectParentName, propertyNames);

            return(new List <WmiObject>(new WmiObject[] { newWmiObject }));
        }
示例#2
0
        private void FillItemWithApplicationAttributes(FileItemSystemData fileSystemData, string path)
        {
            WmiInvokeMethodInfo invokeMethodInfo = this.CreateInvokeMethodInfoToGetFileSecurity(path);

            #region Not Implemented

            /* #ToDo Review this method.
             * //ManagementBaseObject secutiryDescriptor = (ManagementBaseObject)this.WmiDataProvider.InvokeMethodByWmiPath(invokeMethodInfo);
             * //ManagementBaseObject descriptor = (ManagementBaseObject)secutiryDescriptor.Properties["Descriptor"].Value;
             * //ManagementBaseObject owner = (ManagementBaseObject)descriptor.Properties["Owner"].Value;
             * //fileSystemData.Owner = String.Format("{0}\\{1}", owner.Properties["Domain"].Value, owner.Properties["Name"].Value);
             *
             * //fileSystemData.MS_Checksum = "[NOT IMPLEMENTED]";
             * //fileSystemData.DevelopmentClass = "[NOT IMPLEMENTED]";
             * //fileSystemData.InternalName = "[NOT IMPLEMENTED]";
             * //fileSystemData.Language = "[NOT IMPLEMENTED]";
             * //fileSystemData.OriginalFilename = "[NOT IMPLEMENTED]";
             * //fileSystemData.ProductName = "[NOT IMPLEMENTED]";
             * //fileSystemData.ProductVersion = "[NOT IMPLEMENTED]";
             */
            #endregion
        }
示例#3
0
        public virtual object InvokeMethodByWmiPath(WmiInvokeMethodInfo wmiInvokeMethodInfo)
        {
            ManagementPath mngPath = this.getManagementPath(wmiInvokeMethodInfo.ClassName, wmiInvokeMethodInfo.PathName, wmiInvokeMethodInfo.PathValue);
            ManagementObject mngObject = new ManagementObject(this._connectionScope, mngPath, null);
            object methodReturn = null;
            try
            {
                methodReturn = mngObject.InvokeMethod(wmiInvokeMethodInfo.MethodName, null, null);
                if (methodReturn == null)
                    throw new InvalidInvokeMethodException(mngPath.RelativePath, wmiInvokeMethodInfo.MethodName);
            }
            catch (ManagementException)
            {
                throw new InvalidInvokeMethodException(mngPath.RelativePath, wmiInvokeMethodInfo.MethodName);
            }



            if (wmiInvokeMethodInfo.ShouldBeReturnManagementObjects())
                return methodReturn;


            ManagementBaseObject systemObject = (ManagementBaseObject)methodReturn;
            string fullObjectParentName = wmiInvokeMethodInfo.OutParameters.ParentObjectNames.First();
            ManagementBaseObject currentObject = (ManagementBaseObject)systemObject.Properties[fullObjectParentName].Value;

            for (int i = 1; i < wmiInvokeMethodInfo.OutParameters.ParentObjectNames.Count; i++)
            {
                string currentObjectName = wmiInvokeMethodInfo.OutParameters.ParentObjectNames.ElementAt(i);
                object currentProperty = currentObject.Properties[currentObjectName].Value;
                bool IsCurrObjList = (currentProperty is IEnumerable<ManagementBaseObject>);

                currentObject = IsCurrObjList ? this.getNewCurrentObjByFilter(currentProperty, wmiInvokeMethodInfo.Filter) : (ManagementBaseObject)currentProperty;
                fullObjectParentName = fullObjectParentName + "." + currentObjectName;
            }

            if (currentObject == null)
                throw new InvalidInvokeMethodFilterException(mngPath.RelativePath, wmiInvokeMethodInfo.MethodName);

            IList<String> propertyNames = wmiInvokeMethodInfo.OutParameters.PropertyNames;
            var newWmiObject = this.createWmiObjectWithProperties(currentObject, fullObjectParentName, propertyNames);
            return new List<WmiObject>(new WmiObject[] { newWmiObject });
        }