Skip to content

Commit

Permalink
more debug output, exact HardwareID matches to troubleshoot #59
Browse files Browse the repository at this point in the history
Matching device HardwareIDs with wildcards was added in f59ea57 and
e4e28bc, but maybe mistakenly so. HardwareIDs can contain * when I
thought it was a wildcard added by Lenovo

https://learn.microsoft.com/en-us/windows-hardware/drivers/install/generic-identifiers
  • Loading branch information
jantari committed Nov 22, 2022
1 parent e06b4a9 commit 678af07
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions private/Test-MachineSatisfiesDependency.ps1
Expand Up @@ -44,16 +44,31 @@
$DevicesMatched = [System.Collections.Generic.List[object]]::new()

:NextDevice foreach ($DeviceInMachine in $CachedHardwareTable['_PnPID']) {
[bool]$DeviceHwIdWildcardMatched = $false

foreach ($HardwareInMachine in $DeviceInMachine.HardwareID) {
# A _Driver node can have multiple 'HardwareID' child nodes, e.g. https://download.lenovo.com/pccbbs/mobiles/r1kwq15w_2_.xml
foreach ($HardwareID in $Dependency.HardwareID.'#cdata-section') {
# Lenovo HardwareIDs can contain wildcards (*) so we have to compare with "-like"
if ($HardwareInMachine -like "*$HardwareID*") {
Write-Debug "$('- ' * $DebugIndent)Matched device '$HardwareInMachine' with required '$HardwareID'"
# Matching with wildcards may have been a mistake, some HardwareIDs just contain a * (star).
# Try exact equal matches first and fall back to wildcard only when needed. I want to see how often that happens.
if ($HardwareInMachine -eq "$HardwareID") {
Write-Debug "$('- ' * $DebugIndent)Matched device '$HardwareInMachine' with required '$HardwareID' (EXACT)"
$DevicesMatched.Add($DeviceInMachine)
continue NextDevice
}
# Lenovo HardwareIDs can contain wildcards (*) so we have to compare with "-like"
if ($HardwareInMachine -like "*$HardwareID*") {
Write-Debug "$('- ' * $DebugIndent)Matched device '$HardwareInMachine' with required '$HardwareID' (WILDCARD)"
$DeviceHwIdWildcardMatched = $true
}
}
}

# To preserve the old behavior whilst fully testing the new, do add devices that were only matched via wildcards
if ($DeviceHwIdWildcardMatched) {
Write-Debug "$('- ' * $DebugIndent)Adding device - HardwareIDs matched only when using wildcards"
$DevicesMatched.Add($DeviceInMachine)
}
}

if ($DevicesMatched.Count -ge 1) {
Expand All @@ -63,6 +78,7 @@

$TestResults = [System.Collections.Generic.List[bool]]::new()
foreach ($Device in $DevicesMatched) {
Write-Debug "$('- ' * $DebugIndent)Testing $($Device.DeviceId)"
# First, check if there is a driver installed for the device at all before proceeding (issue#24)
if ($Device.Problem -eq 'CM_PROB_FAILED_INSTALL') {
[string]$HexDeviceProblemStatus = '0x{0:X8}' -f (Get-PnpDeviceProperty -InputObject $Device -KeyName 'DEVPKEY_Device_ProblemStatus').Data
Expand Down Expand Up @@ -118,7 +134,9 @@
# AFAIK it is not possible to detect with 100% certainty that a driver is generic/inbox and even if - it's not always a problem.
# So this information should only be used for informaing the user or as an aid in making non-critical decisions,
# do not rely on this detection/boolean to be accurate!
[byte]$DriverMatchTypeScore = (Get-PnpDeviceProperty -InputObject $Device -KeyName 'DEVPKEY_Device_DriverRank').Data -shr 12 -band 0xF
[UInt32]$DriverRank = (Get-PnpDeviceProperty -InputObject $Device -KeyName 'DEVPKEY_Device_DriverRank').Data
[byte]$DriverMatchTypeScore = $DriverRank -shr 12 -band 0xF
Write-Debug "Device '$($Device.Name)' DriverRank is 0x$('{0:X8}' -f $DriverRank)"
if ($DriverMatchTypeScore -ge 2) {
Write-Verbose "Device '$($Device.Name)' may currently be using a generic or inbox driver"
}
Expand Down Expand Up @@ -163,8 +181,10 @@
if ($DriverVersion) {
Write-Debug "$('- ' * $DebugIndent)[Got: $DriverVersion, Expected: $($Dependency.Version)]"
if ((Test-VersionPattern -LenovoString $Dependency.Version -SystemString $DriverVersion) -eq 0) {
Write-Debug "$('- ' * $DebugIndent)Passed DriverVersion test"
$TestResults.Add($true)
} else {
Write-Debug "$('- ' * $DebugIndent)Failed DriverVersion test"
$TestResults.Add($false)
}
} else {
Expand Down

1 comment on commit 678af07

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSScriptAnalyzer results as of this commit:

  • 2 Information
  • 8 Warning
See details
Location : ./public/Install-LSUpdate.ps1 [135, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Install-LSUpdate.ps1 [172, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Set-LSUClientConfiguration.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-LSUClientConfiguration' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./private/Split-ExecutableAndArguments.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Split-ExecutableAndArguments' uses a plural noun. A singular noun
            should be used instead.

Location : ./private/Invoke-PackageCommand.ps1 [293, 25]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Resolve-XMLDependencies.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Resolve-XMLDependencies' uses a plural noun. A singular noun shou
           ld be used instead.

Location : ./private/Set-BIOSUpdateRegistryFlag.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-BIOSUpdateRegistryFlag' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./private/Debug-LongRunningProcess.ps1 [44, 13]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Debug-LongRunningProcess.ps1 [126, 82]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'lParam' has been declared but not used. 

Location : ./private/Compare-Array.ps1 [30, 17]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'in' has been declared but not used.

Please sign in to comment.