Пример #1
0
        /// <summary>
        /// Get the List of HotFixes installed on the Local Machine.
        /// </summary>
        protected override void BeginProcessing()
        {
            foreach (string computer in ComputerName)
            {
                bool              foundRecord = false;
                StringBuilder     QueryString = new StringBuilder();
                ConnectionOptions conOptions  = ComputerWMIHelper.GetConnectionOptions(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential);
                ManagementScope   scope       = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), conOptions);
                scope.Connect();
                if (Id != null)
                {
                    QueryString.Append("Select * from Win32_QuickFixEngineering where (");
                    for (int i = 0; i <= Id.Length - 1; i++)
                    {
                        QueryString.Append("HotFixID= '");
                        QueryString.Append(Id[i].ToString().Replace("'", "\\'"));
                        QueryString.Append("'");
                        if (i < Id.Length - 1)
                        {
                            QueryString.Append(" Or ");
                        }
                    }

                    QueryString.Append(")");
                }
                else
                {
                    QueryString.Append("Select * from Win32_QuickFixEngineering");
                    foundRecord = true;
                }

                _searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(QueryString.ToString()));
                foreach (ManagementObject obj in _searchProcess.Get())
                {
                    if (Description != null)
                    {
                        if (!FilterMatch(obj))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        _inputContainsWildcard = true;
                    }

                    // try to translate the SID to a more friendly username
                    // just stick with the SID if anything goes wrong
                    string installed = (string)obj["InstalledBy"];
                    if (!String.IsNullOrEmpty(installed))
                    {
                        try
                        {
                            SecurityIdentifier secObj = new SecurityIdentifier(installed);
                            obj["InstalledBy"] = secObj.Translate(typeof(NTAccount));;
                        }
                        catch (IdentityNotMappedException) // thrown by SecurityIdentifier.Translate
                        {
                        }
                        catch (SystemException) // thrown by SecurityIdentifier.constr
                        {
                        }
                        //catch (ArgumentException) // thrown (indirectly) by SecurityIdentifier.constr (on XP only?)
                        //{ catch not needed - this is already caught as SystemException
                        //}
                        //catch (PlatformNotSupportedException) // thrown (indirectly) by SecurityIdentifier.Translate (on Win95 only?)
                        //{ catch not needed - this is already caught as SystemException
                        //}
                        //catch (UnauthorizedAccessException) // thrown (indirectly) by SecurityIdentifier.Translate
                        //{ catch not needed - this is already caught as SystemException
                        //}
                    }

                    WriteObject(obj);
                    foundRecord = true;
                }

                if (!foundRecord && !_inputContainsWildcard)
                {
                    Exception Ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
                    WriteError(new ErrorRecord(Ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
                }

                if (_searchProcess != null)
                {
                    this.Dispose();
                }
            }
        }//end of BeginProcessing method