Beispiel #1
0
        internal static bool EnumDriverPackages(
            IntPtr driverStoreHandle,
            string driverStoreFilename,
            DriverPackageInfo pDriverPackageInfo,
            IntPtr lParam)
        {
            List <DriverStoreEntry> driverStoreEntries = (List <DriverStoreEntry>)GCHandle.FromIntPtr(lParam).Target;
            var driverClassGuid = GetObjectPropertyInfo <Guid>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_ClassGuid);

            DriverStoreEntry driverStoreEntry = new DriverStoreEntry
            {
                DriverClass          = ConfigManager.GetClassProperty <string>(driverClassGuid, DeviceHelper.DEVPKEY_DeviceClass_Name),
                DriverExtensionId    = GetObjectPropertyInfo <Guid>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_ExtensionId),
                DriverInfName        = Path.GetFileName(driverStoreFilename),
                DriverPublishedName  = pDriverPackageInfo.PublishedInfName,
                DriverPkgProvider    = GetObjectPropertyInfo <string>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_ProviderName),
                DriverSignerName     = GetObjectPropertyInfo <string>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_SignerName),
                DriverDate           = GetObjectPropertyInfo <DateTime>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_DriverDate),
                DriverVersion        = GetObjectPropertyInfo <Version>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_DriverVersion),
                DriverFolderLocation = Path.GetDirectoryName(driverStoreFilename),
                DriverSize           = DriverStoreRepository.GetFolderSize(new DirectoryInfo(Path.GetDirectoryName(driverStoreFilename))),
                BootCritical         = GetObjectPropertyInfo <bool?>(driverStoreHandle, driverStoreFilename, DeviceHelper.DEVPKEY_DriverPackage_BootCritical),
            };

            driverStoreEntries.Add(driverStoreEntry);

            return(true);
        }
        public List <DriverStoreEntry> EnumeratePackages()
        {
            List <DriverStoreEntry> driverStoreEntries = new List <DriverStoreEntry>();

            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = this.GetSession())
                {
                    List <DeviceDriverInfo> driverInfo = this.Type == DriverStoreType.Online
                        ? ConfigManager.GetDeviceDriverInfo()
                        : null;

                    foreach (var driverPackage in DismApi.GetDrivers(session, false))
                    {
                        DriverStoreEntry driverStoreEntry = new DriverStoreEntry
                        {
                            DriverClass          = driverPackage.ClassDescription,
                            DriverInfName        = Path.GetFileName(driverPackage.OriginalFileName),
                            DriverPublishedName  = driverPackage.PublishedName,
                            DriverPkgProvider    = driverPackage.ProviderName,
                            DriverSignerName     = driverPackage.DriverSignature == DismDriverSignature.Signed ? SetupAPI.GetDriverSignerInfo(driverPackage.OriginalFileName) : string.Empty,
                            DriverDate           = driverPackage.Date,
                            DriverVersion        = driverPackage.Version,
                            DriverFolderLocation = Path.GetDirectoryName(driverPackage.OriginalFileName),
                            DriverSize           = DriverStoreRepository.GetFolderSize(new DirectoryInfo(Path.GetDirectoryName(driverPackage.OriginalFileName))),
                            BootCritical         = driverPackage.BootCritical,
                            Inbox = driverPackage.InBox,
                        };

                        var deviceInfo = driverInfo?.OrderByDescending(d => d.IsPresent)?.FirstOrDefault(e =>
                                                                                                         string.Equals(Path.GetFileName(e.DriverInf), driverStoreEntry.DriverPublishedName, StringComparison.OrdinalIgnoreCase) &&
                                                                                                         e.DriverVersion == driverStoreEntry.DriverVersion &&
                                                                                                         e.DriverDate == driverStoreEntry.DriverDate);

                        driverStoreEntry.DeviceName    = deviceInfo?.DeviceName;
                        driverStoreEntry.DevicePresent = deviceInfo?.IsPresent;

                        driverStoreEntries.Add(driverStoreEntry);
                    }
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(driverStoreEntries);
        }
        public List <DriverStoreEntry> EnumeratePackages()
        {
            List <DriverStoreEntry> driverStoreEntries = new List <DriverStoreEntry>();

            DismApi.Initialize(DismLogLevel.LogErrors);

            try
            {
                using (DismSession session = DismApi.OpenOnlineSession())
                {
                    foreach (var driverPackage in DismApi.GetDrivers(session, false))
                    {
                        driverStoreEntries.Add(new DriverStoreEntry
                        {
                            DriverClass          = driverPackage.ClassDescription,
                            DriverInfName        = Path.GetFileName(driverPackage.OriginalFileName),
                            DriverPublishedName  = driverPackage.PublishedName,
                            DriverPkgProvider    = driverPackage.ProviderName,
                            DriverSignerName     = driverPackage.DriverSignature.ToString(),
                            DriverDate           = driverPackage.Date,
                            DriverVersion        = driverPackage.Version,
                            DriverFolderLocation = Path.GetDirectoryName(driverPackage.OriginalFileName),
                            DriverSize           = DriverStoreRepository.GetFolderSize(new DirectoryInfo(Path.GetDirectoryName(driverPackage.OriginalFileName))),
                            BootCritical         = driverPackage.BootCritical,
                            Inbox = driverPackage.InBox,
                        });
                    }
                }
            }
            finally
            {
                DismApi.Shutdown();
            }

            return(driverStoreEntries);
        }