Esempio n. 1
0
        private object DataReaderToObject(SqlCeDataReader reader, EntityType entity)
        {
            object entityObject  = null;

            switch (entity)
            {
                case EntityType.Processor:
                    entityObject = new EntProcessor();
                    break;
                case EntityType.OS:
                    entityObject = new EntOS();
                    break;
                case EntityType.Bios:
                    entityObject = new EntBios();
                    break;
                case EntityType.MotherBoard:
                    entityObject = new EntMotherBoard();
                    break;
                case EntityType.Disk:
                    entityObject = new EntDisk();
                    break;
                case EntityType.Memory:
                    entityObject = new EntMemory();
                    break;
                case EntityType.LogicalDrive:
                    entityObject = new EntLogicalDrive();
                    break;
                case EntityType.CDRom:
                    entityObject = new EntCDRom();
                    break;
                case EntityType.Video:
                    entityObject = new EntVideo();
                    break;
                case EntityType.Multimedia:
                    entityObject = new EntMultimedia();
                    break;
                case EntityType.Monitor:
                    entityObject = new EntMonitor();
                    break;
                case EntityType.Share:
                    entityObject = new EntShare();
                    break;
                case EntityType.StartUp:
                    entityObject = new EntStartUp();
                    break;
                case EntityType.Hotfix:
                    entityObject = new EntHotfixes();
                    break;
                case EntityType.Processes:
                    entityObject = new EntProcesses();
                    break;
                case EntityType.Softwares:
                    entityObject = new EntSoftwares();
                    break;
                case EntityType.Services:
                    entityObject = new EntServices();
                    break;
                case EntityType.IPRoutes:
                    entityObject = new EntIPRoutes();
                    break;
                case EntityType.EnvironmentVar:
                    entityObject = new EntEnvironmentVars();
                    break;
                case EntityType.Computer:
                    entityObject = new EntComputer();
                    break;
                case EntityType.Printer:
                    entityObject = new EntPrinter();
                    break;
                case EntityType.UserGroup:
                    entityObject = new EntUserGroups();
                    break;
                case EntityType.NetworkAdapter:
                    entityObject = new EntNetworkAdapter();
                    break;
            }

            Type t = entityObject.GetType();
            PropertyInfo[] pi = t.GetProperties();

            foreach (PropertyInfo prop in pi)
            {
                if (prop.Name == "ClassName" || prop.Name == "Icon" || prop.Name == "NodeName")
                    continue;

                switch (prop.PropertyType.Name)
                {
                    case "String":
                        string strValue = reader.GetString(reader.GetOrdinal(prop.Name));
                        prop.SetValue(entityObject, strValue, null);
                        break;
                    case "Int32":
                        int intValue = reader.GetInt32(reader.GetOrdinal(prop.Name));
                        prop.SetValue(entityObject, intValue, null);
                        break;
                    case "Double":
                        double dValue = reader.GetDouble(reader.GetOrdinal(prop.Name));
                        prop.SetValue(entityObject, dValue, null);
                        break;

                    case "DateTime":
                        DateTime dtValue = DateTime.MinValue;
                        if ( reader.GetValue(reader.GetOrdinal(prop.Name))== DBNull.Value)
                        {
                            dtValue = DateTime.MinValue;
                        }
                        else
                        {
                            dtValue = reader.GetDateTime(reader.GetOrdinal(prop.Name));
                        }
                        prop.SetValue(entityObject, dtValue, null);
                        break;
                    case "Boolean":
                        bool bValue = reader.GetBoolean(reader.GetOrdinal(prop.Name));
                        prop.SetValue(entityObject, bValue, null);
                        break;

                }
            }

            return entityObject;
        }
Esempio n. 2
0
        public static List<EntSoftwares> FillDetails(ManagementScope scope, string keyPath)
        {
            _logger.Info("Collecting software installed details for machine " + scope.Path.Server);

            List<EntSoftwares> lstSoftwares = new List<EntSoftwares>();
            ManagementPath mypath = new ManagementPath("StdRegProv");
            const uint HKEY_LOCAL_MACHINE = unchecked((uint)0x80000002);
            ManagementClass wmiRegistry = new ManagementClass(scope, mypath, null);

            object[] methodArgs = new object[] { HKEY_LOCAL_MACHINE, keyPath, null };
            uint returnValue = (uint)wmiRegistry.InvokeMethod("EnumKey", methodArgs);

            try
            {
                if (null != methodArgs[2])
                {

                    string[] subKeys = methodArgs[2] as String[];

                    if (subKeys == null)
                        return lstSoftwares;

                    ManagementBaseObject inParam =
                    wmiRegistry.GetMethodParameters("GetStringValue");

                    inParam["hDefKey"] = HKEY_LOCAL_MACHINE;

                    string keyName = "";

                    ManagementBaseObject outParam = null;
                    foreach (string subKey in subKeys)
                    {
                        string subKeyName = string.Format(@"{0}\{1}", keyPath, subKey);

                        keyName = "DisplayName";
                        inParam["sSubKeyName"] = subKeyName;
                        inParam["sValueName"] = keyName;
                        outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);
                        if (outParam != null && (uint)outParam["ReturnValue"] == 0)
                        {
                            if (outParam["sValue"].ToString().StartsWith("IBM Lotus") != true)
                                continue;

                            EntSoftwares objEntSoftwares = new EntSoftwares();
                            objEntSoftwares.Name = outParam["sValue"].ToString();

                            keyName = "DisplayVersion";
                            inParam["sSubKeyName"] = subKeyName;
                            inParam["sValueName"] = keyName;
                            outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);
                            if ((uint)outParam["ReturnValue"] == 0)
                            {
                                objEntSoftwares.Version = outParam["sValue"].ToString();
                            }
                            else
                            {
                                objEntSoftwares.Version = "";
                            }

                            keyName = "InstallLocation";
                            inParam["sSubKeyName"] = subKeyName;
                            inParam["sValueName"] = keyName;
                            outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);
                            if ((uint)outParam["ReturnValue"] == 0)
                            {
                                objEntSoftwares.Location = outParam["sValue"].ToString();
                            }
                            else
                            {
                                objEntSoftwares.Location = "";
                            }

                            keyName = "InstallDate";
                            inParam["sSubKeyName"] = subKeyName;
                            inParam["sValueName"] = keyName;
                            outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);
                            if ((uint)outParam["ReturnValue"] == 0)
                            {
                                objEntSoftwares.InstallDate = WMIUtil.ToShortDateTime(outParam["sValue"].ToString());
                            }
                            else
                            {
                                objEntSoftwares.InstallDate = DateTime.MinValue;
                            }

                            lstSoftwares.Add(objEntSoftwares);

                            break;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                _logger.Error("Exception in installed software collection " + e.Message);
            }
            return lstSoftwares;
        }