Exemplo n.º 1
0
        private void ConnectGetWMI()
        {
            string wmiQueryString;
            GetWmiObjectCommand getWmiObjectCommand = (GetWmiObjectCommand)this.wmiObject;

            this.state = WmiState.Running;
            this.RaiseWmiOperationState(null, WmiState.Running);
            ConnectionOptions connectionOption = getWmiObjectCommand.GetConnectionOption();
            SwitchParameter   list             = getWmiObjectCommand.List;

            if (!list.IsPresent)
            {
                if (string.IsNullOrEmpty(getWmiObjectCommand.Query))
                {
                    wmiQueryString = this.GetWmiQueryString();
                }
                else
                {
                    wmiQueryString = getWmiObjectCommand.Query;
                }
                string      str         = wmiQueryString;
                ObjectQuery objectQuery = new ObjectQuery(str.ToString());
                try
                {
                    ManagementScope    managementScope   = new ManagementScope(WMIHelper.GetScopeString(this.computerName, getWmiObjectCommand.Namespace), connectionOption);
                    EnumerationOptions enumerationOption = new EnumerationOptions();
                    enumerationOption.UseAmendedQualifiers = getWmiObjectCommand.Amended;
                    enumerationOption.DirectRead           = getWmiObjectCommand.DirectRead;
                    ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, objectQuery, enumerationOption);
                    for (int i = 0; i < this.cmdCount; i++)
                    {
                        managementObjectSearcher.Get(this.results);
                    }
                }
                catch (ManagementException managementException1)
                {
                    ManagementException managementException = managementException1;
                    this.internalException = managementException;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (COMException cOMException1)
                {
                    COMException cOMException = cOMException1;
                    this.internalException = cOMException;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                catch (UnauthorizedAccessException unauthorizedAccessException1)
                {
                    UnauthorizedAccessException unauthorizedAccessException = unauthorizedAccessException1;
                    this.internalException = unauthorizedAccessException;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                }
                return;
            }
            else
            {
                if (getWmiObjectCommand.ValidateClassFormat())
                {
                    try
                    {
                        SwitchParameter recurse = getWmiObjectCommand.Recurse;
                        if (!recurse.IsPresent)
                        {
                            ManagementScope managementScope1 = new ManagementScope(WMIHelper.GetScopeString(this.computerName, getWmiObjectCommand.Namespace), connectionOption);
                            managementScope1.Connect();
                            ManagementObjectSearcher objectList = getWmiObjectCommand.GetObjectList(managementScope1);
                            if (objectList != null)
                            {
                                objectList.Get(this.results);
                            }
                            else
                            {
                                throw new ManagementException();
                            }
                        }
                        else
                        {
                            ArrayList arrayLists  = new ArrayList();
                            ArrayList arrayLists1 = new ArrayList();
                            ArrayList arrayLists2 = new ArrayList();
                            int       num         = 0;
                            arrayLists.Add(getWmiObjectCommand.Namespace);
                            bool flag = true;
                            while (num < arrayLists.Count)
                            {
                                string          item             = (string)arrayLists[num];
                                ManagementScope managementScope2 = new ManagementScope(WMIHelper.GetScopeString(this.computerName, item), connectionOption);
                                managementScope2.Connect();
                                ManagementClass managementClass = new ManagementClass(managementScope2, new ManagementPath("__Namespace"), new ObjectGetOptions());
                                foreach (ManagementBaseObject instance in managementClass.GetInstances())
                                {
                                    if (getWmiObjectCommand.IsLocalizedNamespace((string)instance["Name"]))
                                    {
                                        continue;
                                    }
                                    arrayLists.Add(string.Concat(item, "\\", instance["Name"]));
                                }
                                if (!flag)
                                {
                                    arrayLists1.Add(this.Job.GetNewSink());
                                }
                                else
                                {
                                    flag = false;
                                    arrayLists1.Add(this.results);
                                }
                                arrayLists2.Add(managementScope2);
                                num++;
                            }
                            if (arrayLists1.Count != arrayLists.Count || arrayLists2.Count != arrayLists.Count)
                            {
                                this.internalException = new InvalidOperationException();
                                this.state             = WmiState.Failed;
                                this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                                return;
                            }
                            else
                            {
                                num = 0;
                                while (num < arrayLists.Count)
                                {
                                    ManagementObjectSearcher objectList1 = getWmiObjectCommand.GetObjectList((ManagementScope)arrayLists2[num]);
                                    if (objectList1 != null)
                                    {
                                        if (!flag)
                                        {
                                            objectList1.Get((ManagementOperationObserver)arrayLists1[num]);
                                        }
                                        else
                                        {
                                            flag = false;
                                            objectList1.Get(this.results);
                                        }
                                        num++;
                                    }
                                    else
                                    {
                                        num++;
                                    }
                                }
                            }
                        }
                    }
                    catch (ManagementException managementException3)
                    {
                        ManagementException managementException2 = managementException3;
                        this.internalException = managementException2;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    catch (COMException cOMException3)
                    {
                        COMException cOMException2 = cOMException3;
                        this.internalException = cOMException2;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    catch (UnauthorizedAccessException unauthorizedAccessException3)
                    {
                        UnauthorizedAccessException unauthorizedAccessException2 = unauthorizedAccessException3;
                        this.internalException = unauthorizedAccessException2;
                        this.state             = WmiState.Failed;
                        this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    }
                    return;
                }
                else
                {
                    object[] @class = new object[1];
                    @class[0] = getWmiObjectCommand.Class;
                    ArgumentException argumentException = new ArgumentException(string.Format(Thread.CurrentThread.CurrentCulture, "Class", @class));
                    this.internalException = argumentException;
                    this.state             = WmiState.Failed;
                    this.RaiseOperationCompleteEvent(null, OperationState.StopComplete);
                    return;
                }
            }
        }