From e1c5dfb76c810526d0d1bcb7d28c06b71cbb314a Mon Sep 17 00:00:00 2001 From: Brian Warren Date: Sun, 6 Apr 2025 22:03:46 -0500 Subject: [PATCH] fixing registry query logic --- ua/registry/qlogic-devapp-tool.ps1 | 214 +++++++++++++++-------------- ua/registry/uasrdev-add.reg | Bin 0 -> 9230 bytes ua/registry/uasrdev-del.reg | Bin 0 -> 6814 bytes 3 files changed, 114 insertions(+), 100 deletions(-) create mode 100644 ua/registry/uasrdev-add.reg create mode 100644 ua/registry/uasrdev-del.reg diff --git a/ua/registry/qlogic-devapp-tool.ps1 b/ua/registry/qlogic-devapp-tool.ps1 index 3a153a9..ce01193 100644 --- a/ua/registry/qlogic-devapp-tool.ps1 +++ b/ua/registry/qlogic-devapp-tool.ps1 @@ -3,28 +3,28 @@ param ( [string] $airline = 'ua', - [Parameter(Mandatory=$true)] - [ValidateSet('query', 'export', 'import', 'delete')] - [string] - $action, - [Parameter(Mandatory=$true)] [ValidateSet('gate', 'checkin')] [string] - $comServerType, + $comType, + + [Parameter(Mandatory=$true)] + [ValidateSet('export', 'import', 'delete', 'createRegFiles')] + [string] + $action, [Parameter(Mandatory=$false)] [ValidateSet('HKEY_LOCAL_MACHINE', 'HKEY_CURRENT_USER', 'HKLM', 'HKCU')] [string] - $registryHive = 'HKEY_LOCAL_MACHINE', + $hive = 'HKEY_LOCAL_MACHINE', [Parameter(Mandatory=$false)] [string] - $comServerDir, + $comDir, [Parameter(Mandatory=$false)] [string] - $comServerFileName, + $comFileName, [Parameter(Mandatory=$false)] [switch] @@ -51,8 +51,9 @@ switch ($airline) { exit 1 } 'ua' { - switch ($comServerType) { + switch ($comType) { 'checkin' { + $appName = 'uasrdev' $clsid = '35578409-F9F5-43e8-A6BD-8B77199ED854' $appId = '91D04D72-DCB6-11D3-957D-00409500D5AD' $classLabel = "QWDev Class" @@ -65,6 +66,7 @@ switch ($airline) { $versionIndependentProgId = 'QSRDevice.QSRDev'; } 'gate' { + $appName = 'uagrdev' $clsid = '3F52625C-F66C-43F5-B538-CDF7331E0B7D' $appId = 'C123476B-ABB6-4bcc-B557-2FDC0CDCD6A8' $classLabel = "QSRDev Class" @@ -85,21 +87,21 @@ switch ($airline) { } switch ($action) { - 'delete' { + 'createRegFiles' { } - 'import' { - if (!$comServerDir) { - Write-Error "Missing COM server directory" - exit 1 - } - if (!$comServerFileName) { - Write-Error "Missing COM server file name" - exit 1 - } + 'delete' { } 'export' { } - 'query' { + 'import' { + if (!$comDir) { + Write-Error "Missing COM server directory" + exit 1 + } + if (!$comFileName) { + Write-Error "Missing COM server file name" + exit 1 + } } default { Write-Error "Unknown action: $action" @@ -107,58 +109,57 @@ switch ($action) { } } -switch ($registryHive) { +switch ($hive) { 'HKCU' { - $registryHiveShort = 'HKCU' - $registryHive = 'HKEY_CURRENT_USER' + $hiveShort = 'HKCU' + $hive = 'HKEY_CURRENT_USER' } 'HKLM' { - $registryHiveShort = 'HKLM' - $registryHive = 'HKEY_LOCAL_MACHINE' + $hiveShort = 'HKLM' + $hive = 'HKEY_LOCAL_MACHINE' } 'HKEY_CURRENT_USER' { - $registryHiveShort = 'HKCU' - $registryHive = 'HKEY_CURRENT_USER' + $hiveShort = 'HKCU' + $hive = 'HKEY_CURRENT_USER' } 'HKEY_LOCAL_MACHINE' { - $registryHiveShort = 'HKLM' - $registryHive = 'HKEY_LOCAL_MACHINE' + $hiveShort = 'HKLM' + $hive = 'HKEY_LOCAL_MACHINE' } default { - Write-Error "Invalid registry hive: $registryHive" + Write-Error "Invalid registry hive: $hive" exit 1 } } -$comServerDir = $comServerDir.TrimEnd('\') -$comServerPath = "$comServerDir\$comServerFileName" -if (![System.IO.Path]::IsPathRooted($comServerPath)) { - Write-Error "Provided COM server path is not absolute: $comServerPath" +$comDir = $comDir.TrimEnd('\') +$comPath = "$comDir\$comFileName" +if (![System.IO.Path]::IsPathRooted($comPath)) { + Write-Error "Provided COM server path is not absolute: $comPath" exit 1 } -$comServerNetworkPath = $comServerPath - -if (!(Test-Path $comServerPath)) { - Write-Warning "COM server path does not exist: $comServerPath" +if (!(Test-Path $comPath)) { + Write-Warning "COM server path does not exist: $comPath" } # COM servers use the network path in some registry keys when self-registering, so attempt to discover it. +$comNetworkPath = $comPath try { - $driveLetter = $comServerPath.Substring(0, 1) + $driveLetter = $comPath.Substring(0, 1) $networkPathToDrive = (Get-PSDrive | Where-Object {$_.Name -eq $driveLetter}).DisplayRoot if ($networkPathToDrive) { - $rootPathWithoutDrive = $comServerPath.Substring(2) - $comServerNetworkPath = "$networkPathToDrive$rootPathWithoutDrive" + $rootPathWithoutDrive = $comPath.Substring(2) + $comNetworkPath = "$networkPathToDrive$rootPathWithoutDrive" } } catch { - Write-Error "An error occurred trying to discover network path to COM server at $comServerPath" + Write-Error "An error occurred trying to discover network path to COM server at $comPath" } $progId = "$versionIndependentProgId.1"; $proxyStubClsid32 = '00020420-0000-0000-C000-000000000046' $typeLibVersion = '1.0' -function Get-ClsidKeys { +function Get-ClsidPaths { param( [Parameter(Mandatory=$true)] [string] @@ -183,7 +184,7 @@ function Get-ClsidKeys { Values = @( @{ Name = '(default)' - Value = $comServerPath + Value = $comPath } ) }, @@ -216,7 +217,7 @@ function Get-ClsidKeys { ) } -function Get-InterfaceKeys { +function Get-InterfacePaths { param( [Parameter(Mandatory=$true)] [string] @@ -287,7 +288,7 @@ function Get-InterfaceKeys { ) } -function Get-ProgIdKeys { +function Get-ProgIdPaths { return @( @{ Key = "\SOFTWARE\Classes\$progId" @@ -337,7 +338,7 @@ function Get-ProgIdKeys { ) } -function Get-TypeLibKeys { +function Get-TypeLibPaths { param( [Parameter(Mandatory=$true)] [string] @@ -366,7 +367,7 @@ function Get-TypeLibKeys { Values = @( @{ Name = '(default)' - Value = $comServerNetworkPath + Value = $comNetworkPath } ) }, @@ -384,14 +385,14 @@ function Get-TypeLibKeys { Values = @( @{ Name = '(default)' - Value = "$comServerDir\" + Value = "$comDir\" } ) } ) } -function Get-Keys { +function Get-Paths { param( [Parameter(Mandatory=$false)] [switch] @@ -404,94 +405,79 @@ function Get-Keys { $wow6432Node = '\Wow6432Node\' } - $keys = New-Object System.Collections.Generic.List[System.Object] - $keys.AddRange((Get-ProgIdKeys)) - $keys.AddRange((Get-ClsidKeys -architectureNode $wow6432Node)) - $keys.AddRange((Get-InterfaceKeys -architectureNode $wow6432Node)) - $keys.AddRange((Get-TypeLibKeys -architectureNode $wow6432Node)) + $paths = New-Object System.Collections.Generic.List[System.Object] + $paths.AddRange((Get-ProgIdPaths)) + $paths.AddRange((Get-ClsidPaths -architectureNode $wow6432Node)) + $paths.AddRange((Get-InterfacePaths -architectureNode $wow6432Node)) + $paths.AddRange((Get-TypeLibPaths -architectureNode $wow6432Node)) if ($wow6432Node -ne '\') { if ($bothArchitectures) { - $keys.AddRange((Get-ClsidKeys -architectureNode $wow6432Node)) + $paths.AddRange((Get-ClsidPaths -architectureNode $wow6432Node)) } - $keys.AddRange((Get-InterfaceKeys -architectureNode '\')) - $keys.AddRange((Get-TypeLibKeys -architectureNode '\')) + $paths.AddRange((Get-InterfacePaths -architectureNode '\')) + $paths.AddRange((Get-TypeLibPaths -architectureNode '\')) } - return $keys + return $paths } function Read-Registry { - param( - [Parameter(Mandatory=$false)] - [switch] - $useRegFileFormat = $false - ) - $keys = Get-Keys -bothArchitectures - if ($useRegFileFormat) { - Write-Host 'Windows Registry Editor Version 5.00' - } - foreach ($key in $keys) { - $path = "$($registryHiveShort):\$($key.Key)" + $paths = Get-Paths -bothArchitectures + foreach ($path in $paths) { + $path = "$($hiveShort):\$($path.Key)" try { $foundKey = Get-Item -Path $path -ErrorAction Stop } catch { - Write-Debug "Failed to find $path" + Write-Warning "Failed to find $path" continue } $pathShort = $foundKey.PSPath -replace '^.*::', '' Write-Host - Write-Host "[$pathShort]" + Write-Host $pathShort $itemProperty = Get-ItemProperty -Path $foundKey.PSPath if (!$itemProperty) { continue } foreach ($property in $itemProperty.PSObject.Properties) { - if ($property.Name.StartsWith('PS')) { - continue - } - if ($property.Name -eq '(default)') { - $name = '@' - } else { - $name = """$($property.Name)""" - } - Write-Host "$($name)=""$($property.Value)""" + Write-Host "$($property.Name)=$property.Value" } } } switch ($action) { 'delete' { - $keys = Get-Keys -useRegFileFormat - foreach ($key in $keys) { + $paths = Get-Paths -bothArchitectures + foreach ($path in $paths) { + $path = "$($hiveShort):\$($path.Key)" try { - Write-Debug "Deleting key: $($key.Key)" - # Remove-Item -Path $key.Key -Recurse -Force - # Write-Host "Deleted registry key: $($key.Key)" + $foundKey = Get-Item -Path $path -ErrorAction Stop + #Remove-Item -Path $path -Recurse -Force + Write-Information "Deleted registry key: $foundKey" } catch { - Write-Error "Failed to delete key: $($key.Key)" + Write-Error "Failed to find $path" continue } } - } 'import' { - $keys = Get-Keys - foreach ($key in $keys) { + $paths = Get-Paths + foreach ($path in $paths) { + $path = "$($hiveShort):\$($path.Key)" try { - Write-Debug "Importing key: $($key.Key)" # $newKey = New-Item -Path $keyEl.Key -Force - # Write-Host "Created registry key: $($newKey.PSPath)" + $newKey = Get-Item -Path $path -ErrorAction Stop + Write-Information "Imported key: $newKey" } catch { - Write-Error "Failed to create key: $($key.Key)" + Write-Error "Failed to import key: $path" continue } foreach ($value in $key.Values) { try { - Write-Debug "Importing value: $($value.Name):$($value.Value)" - #New-ItemProperty -Path $key.Key -Name $value.Name -Value $value.Value -PropertyType 'String' -Force - #Write-Host "Created registry value: $($value.Name) in $($key.Key)" + #$newItem = New-ItemProperty -Path $key.Key -Name $value.Name -Value $value.Value -PropertyType 'String' -Force + #Write-Information "Imported value: $newItem" + Write-Information "Imported value: $($value.Name) in $($key.Key)" } catch { Write-Error "Failed to create entry: $($value.Name) in $($key.Key)" @@ -501,11 +487,39 @@ switch ($action) { } } 'export' { - Read-Registry -useRegFileFormat - } - 'query' { Read-Registry } + 'createRegFiles' { + $outFileAdd = "$appName-add.reg" + $outFileDel = "$appName-del.reg" + $paths = Get-Paths + if (Test-Path $outFileAdd) { + try { + Remove-Item -Path $outFileAdd -ErrorAction Stop + } + catch { + Write-Error "Failed to delete existing file: $outFileAdd" + exit 1 + } + } + Write-Output 'Windows Registry Editor Version 5.00' > $outFileAdd + Write-Output 'Windows Registry Editor Version 5.00' > $outFileDel + foreach ($pathItem in $paths) { + $path = "$($hive)$($pathItem.Key)" + Write-Output '' >> $outFileAdd + Write-Output "[$path]" >> $outFileAdd + Write-Output "[-$path]" >> $outFileDel + foreach ($valueItem in $pathItem.Values) { + if ($valueItem.Name -eq '(default)') { + $name = '@' + } else { + $name = """$($valueItem.Name)""" + } + $value = $valueItem.Value.Replace('\', '\\').Replace('"', '\"') + Write-Output "$name=""$value""" >> $outFileAdd + } + } + } default { Write-Error "Unknown action: $action" exit 1 diff --git a/ua/registry/uasrdev-add.reg b/ua/registry/uasrdev-add.reg new file mode 100644 index 0000000000000000000000000000000000000000..f76b7906c8daf49ad9aaa96cf4b78d7166432c38 GIT binary patch literal 9230 zcmd^@?N8cJ6vofzCHo%;-yxKO&?QU8>ohZNLm64t#h})OWQqfIF2sL*+wa_hw&>zM z++G#ZK<``2JulC5pTnQu0~yJw9LZRI%2aaFlSsZXHkEUk$S+1Z%#P@d>F4AV^Al!A z^iSzmr6?t?m-51VzR0G$cwz8<|D*`wc=UD`bfxxbe#V*_cJ`H;2WWypJ{ zyno7ykF4oQo8BeAb;!M#8Y_w?U(GMRk=K%EZZKb+OS~)pDEm@tw%Pv{J4)_xCO-bE zN=@og!DoRK@It_+N~^+b#7qI7Y)F%53-p?-u3>Ay)nTm8+KOCb@nd*gExRE8aTX+P zdnjJ+_nY3`)5wnJnHdAa4jU#z%V2p7BSc{IHp@e?ncM#xxjaZY<5HaE4GYXbiAS%* zUfbZN42Ih5vk9UK%;=m?D=;WjgeiB$Sge|Mo0$fyvOt(?KZdZ-815Xxt-C~Q0+;Hy zk6)5LZpka68N%_AoZwGw_wmBwUf}6IUfzR&bj-(p%D>*tikPcA@Pf`C!Vwx5j_chDeYYtmYo-K0mnk_6K}B=JZ_V{fD?weYr~ZPl)je*H8|~yl9?l zdS2O52kv9LhZZ`+mTlC?!4i7(RIZcfEf}W>rzqQa^z=**K*O;a^BLFEJpc`D+CFz5 zlqv6&xvxS7q}Ab;QI?VMn`+F6{<+*miHpq8y(qs;h{n+9Nj8L^d6qwb=bwT0n4a#tW>7hhh016A!> z3moB#^qDdvtMw}LshIEhtktn(t7TRt$KvPW?+Si*c@k&u!+-P03~$-5n$Mahv#Q|gJQ47$A~cP>ea_z7 zO0Z+}j^cjmkX`T3A$#_&FAi<`aQ$$YwpdR;dwdgD6E4p2EUgIP6RlN}wb5Peo|~`A zQ4htMFgI6)s(bZ6Gk4s&*g>pH?Z$NBjqt`Js}f(eDCGan5t?vWx2#t!>?VJ@;G-dL zQH@Dtl~xWXn^XhasN^;(q?fYQWmef|pZgWfbF7`Rwq%vGS@yn4vrm#6Y-*Dj4{mFr z`+a9mzb1Xq#M0&I0BdjJ3c literal 0 HcmV?d00001 diff --git a/ua/registry/uasrdev-del.reg b/ua/registry/uasrdev-del.reg new file mode 100644 index 0000000000000000000000000000000000000000..e1d4a7c518b4383336c58ab3fbbf7a29295ee2cd GIT binary patch literal 6814 zcmds*+iu!G5QhKjNPUOAfRWu04wtsUNmSH>NrI}nib!HAq&BXA^q{D(-uBxKQe}xt z@0y|&;MpB}=im9~VE+7`X{iU@tI~I^b*x;aJ~6k}Ml1bfX3XjmsX{*1HR~%@m&gyu zr|KwVywH(8DA2iHamRbzDAg5D%aLB|68TC~u5%UqzEQ^9OtD=r(EY4APhIo$H5%{G z$u&ay#!h$qc4~7SMf%vnp2pG%wq0ObTl+t9{?A_UZGrFoT%PvKGQOv-PV^FnRRpIsk z@YJj6g{{P;MQCbriM&x8+%%SKYV8=5Q^khhacQyGi zwQMr^Ew%hIj5C=rwfS&J-dt>1n83~e)`i?*SQ+w($&n%5Q|yt2E-@4!H}8VJx~`4``N80>_wi%@ Ht{&$vW32o> literal 0 HcmV?d00001