fixing registry query logic
This commit is contained in:
parent
5a604a6ef0
commit
e1c5dfb76c
@ -3,28 +3,28 @@ param (
|
|||||||
[string]
|
[string]
|
||||||
$airline = 'ua',
|
$airline = 'ua',
|
||||||
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[ValidateSet('query', 'export', 'import', 'delete')]
|
|
||||||
[string]
|
|
||||||
$action,
|
|
||||||
|
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[ValidateSet('gate', 'checkin')]
|
[ValidateSet('gate', 'checkin')]
|
||||||
[string]
|
[string]
|
||||||
$comServerType,
|
$comType,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[ValidateSet('export', 'import', 'delete', 'createRegFiles')]
|
||||||
|
[string]
|
||||||
|
$action,
|
||||||
|
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[ValidateSet('HKEY_LOCAL_MACHINE', 'HKEY_CURRENT_USER', 'HKLM', 'HKCU')]
|
[ValidateSet('HKEY_LOCAL_MACHINE', 'HKEY_CURRENT_USER', 'HKLM', 'HKCU')]
|
||||||
[string]
|
[string]
|
||||||
$registryHive = 'HKEY_LOCAL_MACHINE',
|
$hive = 'HKEY_LOCAL_MACHINE',
|
||||||
|
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[string]
|
[string]
|
||||||
$comServerDir,
|
$comDir,
|
||||||
|
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[string]
|
[string]
|
||||||
$comServerFileName,
|
$comFileName,
|
||||||
|
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[switch]
|
[switch]
|
||||||
@ -51,8 +51,9 @@ switch ($airline) {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
'ua' {
|
'ua' {
|
||||||
switch ($comServerType) {
|
switch ($comType) {
|
||||||
'checkin' {
|
'checkin' {
|
||||||
|
$appName = 'uasrdev'
|
||||||
$clsid = '35578409-F9F5-43e8-A6BD-8B77199ED854'
|
$clsid = '35578409-F9F5-43e8-A6BD-8B77199ED854'
|
||||||
$appId = '91D04D72-DCB6-11D3-957D-00409500D5AD'
|
$appId = '91D04D72-DCB6-11D3-957D-00409500D5AD'
|
||||||
$classLabel = "QWDev Class"
|
$classLabel = "QWDev Class"
|
||||||
@ -65,6 +66,7 @@ switch ($airline) {
|
|||||||
$versionIndependentProgId = 'QSRDevice.QSRDev';
|
$versionIndependentProgId = 'QSRDevice.QSRDev';
|
||||||
}
|
}
|
||||||
'gate' {
|
'gate' {
|
||||||
|
$appName = 'uagrdev'
|
||||||
$clsid = '3F52625C-F66C-43F5-B538-CDF7331E0B7D'
|
$clsid = '3F52625C-F66C-43F5-B538-CDF7331E0B7D'
|
||||||
$appId = 'C123476B-ABB6-4bcc-B557-2FDC0CDCD6A8'
|
$appId = 'C123476B-ABB6-4bcc-B557-2FDC0CDCD6A8'
|
||||||
$classLabel = "QSRDev Class"
|
$classLabel = "QSRDev Class"
|
||||||
@ -85,21 +87,21 @@ switch ($airline) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
'delete' {
|
'createRegFiles' {
|
||||||
}
|
}
|
||||||
'import' {
|
'delete' {
|
||||||
if (!$comServerDir) {
|
|
||||||
Write-Error "Missing COM server directory"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
if (!$comServerFileName) {
|
|
||||||
Write-Error "Missing COM server file name"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
'export' {
|
'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 {
|
default {
|
||||||
Write-Error "Unknown action: $action"
|
Write-Error "Unknown action: $action"
|
||||||
@ -107,58 +109,57 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($registryHive) {
|
switch ($hive) {
|
||||||
'HKCU' {
|
'HKCU' {
|
||||||
$registryHiveShort = 'HKCU'
|
$hiveShort = 'HKCU'
|
||||||
$registryHive = 'HKEY_CURRENT_USER'
|
$hive = 'HKEY_CURRENT_USER'
|
||||||
}
|
}
|
||||||
'HKLM' {
|
'HKLM' {
|
||||||
$registryHiveShort = 'HKLM'
|
$hiveShort = 'HKLM'
|
||||||
$registryHive = 'HKEY_LOCAL_MACHINE'
|
$hive = 'HKEY_LOCAL_MACHINE'
|
||||||
}
|
}
|
||||||
'HKEY_CURRENT_USER' {
|
'HKEY_CURRENT_USER' {
|
||||||
$registryHiveShort = 'HKCU'
|
$hiveShort = 'HKCU'
|
||||||
$registryHive = 'HKEY_CURRENT_USER'
|
$hive = 'HKEY_CURRENT_USER'
|
||||||
}
|
}
|
||||||
'HKEY_LOCAL_MACHINE' {
|
'HKEY_LOCAL_MACHINE' {
|
||||||
$registryHiveShort = 'HKLM'
|
$hiveShort = 'HKLM'
|
||||||
$registryHive = 'HKEY_LOCAL_MACHINE'
|
$hive = 'HKEY_LOCAL_MACHINE'
|
||||||
}
|
}
|
||||||
default {
|
default {
|
||||||
Write-Error "Invalid registry hive: $registryHive"
|
Write-Error "Invalid registry hive: $hive"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$comServerDir = $comServerDir.TrimEnd('\')
|
$comDir = $comDir.TrimEnd('\')
|
||||||
$comServerPath = "$comServerDir\$comServerFileName"
|
$comPath = "$comDir\$comFileName"
|
||||||
if (![System.IO.Path]::IsPathRooted($comServerPath)) {
|
if (![System.IO.Path]::IsPathRooted($comPath)) {
|
||||||
Write-Error "Provided COM server path is not absolute: $comServerPath"
|
Write-Error "Provided COM server path is not absolute: $comPath"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
$comServerNetworkPath = $comServerPath
|
if (!(Test-Path $comPath)) {
|
||||||
|
Write-Warning "COM server path does not exist: $comPath"
|
||||||
if (!(Test-Path $comServerPath)) {
|
|
||||||
Write-Warning "COM server path does not exist: $comServerPath"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# COM servers use the network path in some registry keys when self-registering, so attempt to discover it.
|
# COM servers use the network path in some registry keys when self-registering, so attempt to discover it.
|
||||||
|
$comNetworkPath = $comPath
|
||||||
try {
|
try {
|
||||||
$driveLetter = $comServerPath.Substring(0, 1)
|
$driveLetter = $comPath.Substring(0, 1)
|
||||||
$networkPathToDrive = (Get-PSDrive | Where-Object {$_.Name -eq $driveLetter}).DisplayRoot
|
$networkPathToDrive = (Get-PSDrive | Where-Object {$_.Name -eq $driveLetter}).DisplayRoot
|
||||||
if ($networkPathToDrive) {
|
if ($networkPathToDrive) {
|
||||||
$rootPathWithoutDrive = $comServerPath.Substring(2)
|
$rootPathWithoutDrive = $comPath.Substring(2)
|
||||||
$comServerNetworkPath = "$networkPathToDrive$rootPathWithoutDrive"
|
$comNetworkPath = "$networkPathToDrive$rootPathWithoutDrive"
|
||||||
}
|
}
|
||||||
} catch {
|
} 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";
|
$progId = "$versionIndependentProgId.1";
|
||||||
$proxyStubClsid32 = '00020420-0000-0000-C000-000000000046'
|
$proxyStubClsid32 = '00020420-0000-0000-C000-000000000046'
|
||||||
$typeLibVersion = '1.0'
|
$typeLibVersion = '1.0'
|
||||||
|
|
||||||
function Get-ClsidKeys {
|
function Get-ClsidPaths {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]
|
[string]
|
||||||
@ -183,7 +184,7 @@ function Get-ClsidKeys {
|
|||||||
Values = @(
|
Values = @(
|
||||||
@{
|
@{
|
||||||
Name = '(default)'
|
Name = '(default)'
|
||||||
Value = $comServerPath
|
Value = $comPath
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -216,7 +217,7 @@ function Get-ClsidKeys {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-InterfaceKeys {
|
function Get-InterfacePaths {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]
|
[string]
|
||||||
@ -287,7 +288,7 @@ function Get-InterfaceKeys {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-ProgIdKeys {
|
function Get-ProgIdPaths {
|
||||||
return @(
|
return @(
|
||||||
@{
|
@{
|
||||||
Key = "\SOFTWARE\Classes\$progId"
|
Key = "\SOFTWARE\Classes\$progId"
|
||||||
@ -337,7 +338,7 @@ function Get-ProgIdKeys {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-TypeLibKeys {
|
function Get-TypeLibPaths {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]
|
[string]
|
||||||
@ -366,7 +367,7 @@ function Get-TypeLibKeys {
|
|||||||
Values = @(
|
Values = @(
|
||||||
@{
|
@{
|
||||||
Name = '(default)'
|
Name = '(default)'
|
||||||
Value = $comServerNetworkPath
|
Value = $comNetworkPath
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -384,14 +385,14 @@ function Get-TypeLibKeys {
|
|||||||
Values = @(
|
Values = @(
|
||||||
@{
|
@{
|
||||||
Name = '(default)'
|
Name = '(default)'
|
||||||
Value = "$comServerDir\"
|
Value = "$comDir\"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-Keys {
|
function Get-Paths {
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$false)]
|
[Parameter(Mandatory=$false)]
|
||||||
[switch]
|
[switch]
|
||||||
@ -404,94 +405,79 @@ function Get-Keys {
|
|||||||
$wow6432Node = '\Wow6432Node\'
|
$wow6432Node = '\Wow6432Node\'
|
||||||
}
|
}
|
||||||
|
|
||||||
$keys = New-Object System.Collections.Generic.List[System.Object]
|
$paths = New-Object System.Collections.Generic.List[System.Object]
|
||||||
$keys.AddRange((Get-ProgIdKeys))
|
$paths.AddRange((Get-ProgIdPaths))
|
||||||
$keys.AddRange((Get-ClsidKeys -architectureNode $wow6432Node))
|
$paths.AddRange((Get-ClsidPaths -architectureNode $wow6432Node))
|
||||||
$keys.AddRange((Get-InterfaceKeys -architectureNode $wow6432Node))
|
$paths.AddRange((Get-InterfacePaths -architectureNode $wow6432Node))
|
||||||
$keys.AddRange((Get-TypeLibKeys -architectureNode $wow6432Node))
|
$paths.AddRange((Get-TypeLibPaths -architectureNode $wow6432Node))
|
||||||
if ($wow6432Node -ne '\') {
|
if ($wow6432Node -ne '\') {
|
||||||
if ($bothArchitectures) {
|
if ($bothArchitectures) {
|
||||||
$keys.AddRange((Get-ClsidKeys -architectureNode $wow6432Node))
|
$paths.AddRange((Get-ClsidPaths -architectureNode $wow6432Node))
|
||||||
}
|
}
|
||||||
$keys.AddRange((Get-InterfaceKeys -architectureNode '\'))
|
$paths.AddRange((Get-InterfacePaths -architectureNode '\'))
|
||||||
$keys.AddRange((Get-TypeLibKeys -architectureNode '\'))
|
$paths.AddRange((Get-TypeLibPaths -architectureNode '\'))
|
||||||
}
|
}
|
||||||
return $keys
|
return $paths
|
||||||
}
|
}
|
||||||
|
|
||||||
function Read-Registry {
|
function Read-Registry {
|
||||||
param(
|
$paths = Get-Paths -bothArchitectures
|
||||||
[Parameter(Mandatory=$false)]
|
foreach ($path in $paths) {
|
||||||
[switch]
|
$path = "$($hiveShort):\$($path.Key)"
|
||||||
$useRegFileFormat = $false
|
|
||||||
)
|
|
||||||
$keys = Get-Keys -bothArchitectures
|
|
||||||
if ($useRegFileFormat) {
|
|
||||||
Write-Host 'Windows Registry Editor Version 5.00'
|
|
||||||
}
|
|
||||||
foreach ($key in $keys) {
|
|
||||||
$path = "$($registryHiveShort):\$($key.Key)"
|
|
||||||
try {
|
try {
|
||||||
$foundKey = Get-Item -Path $path -ErrorAction Stop
|
$foundKey = Get-Item -Path $path -ErrorAction Stop
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Debug "Failed to find $path"
|
Write-Warning "Failed to find $path"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
$pathShort = $foundKey.PSPath -replace '^.*::', ''
|
$pathShort = $foundKey.PSPath -replace '^.*::', ''
|
||||||
Write-Host
|
Write-Host
|
||||||
Write-Host "[$pathShort]"
|
Write-Host $pathShort
|
||||||
$itemProperty = Get-ItemProperty -Path $foundKey.PSPath
|
$itemProperty = Get-ItemProperty -Path $foundKey.PSPath
|
||||||
if (!$itemProperty) {
|
if (!$itemProperty) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
foreach ($property in $itemProperty.PSObject.Properties) {
|
foreach ($property in $itemProperty.PSObject.Properties) {
|
||||||
if ($property.Name.StartsWith('PS')) {
|
Write-Host "$($property.Name)=$property.Value"
|
||||||
continue
|
|
||||||
}
|
|
||||||
if ($property.Name -eq '(default)') {
|
|
||||||
$name = '@'
|
|
||||||
} else {
|
|
||||||
$name = """$($property.Name)"""
|
|
||||||
}
|
|
||||||
Write-Host "$($name)=""$($property.Value)"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
'delete' {
|
'delete' {
|
||||||
$keys = Get-Keys -useRegFileFormat
|
$paths = Get-Paths -bothArchitectures
|
||||||
foreach ($key in $keys) {
|
foreach ($path in $paths) {
|
||||||
|
$path = "$($hiveShort):\$($path.Key)"
|
||||||
try {
|
try {
|
||||||
Write-Debug "Deleting key: $($key.Key)"
|
$foundKey = Get-Item -Path $path -ErrorAction Stop
|
||||||
# Remove-Item -Path $key.Key -Recurse -Force
|
#Remove-Item -Path $path -Recurse -Force
|
||||||
# Write-Host "Deleted registry key: $($key.Key)"
|
Write-Information "Deleted registry key: $foundKey"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "Failed to delete key: $($key.Key)"
|
Write-Error "Failed to find $path"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
'import' {
|
'import' {
|
||||||
$keys = Get-Keys
|
$paths = Get-Paths
|
||||||
foreach ($key in $keys) {
|
foreach ($path in $paths) {
|
||||||
|
$path = "$($hiveShort):\$($path.Key)"
|
||||||
try {
|
try {
|
||||||
Write-Debug "Importing key: $($key.Key)"
|
|
||||||
# $newKey = New-Item -Path $keyEl.Key -Force
|
# $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 {
|
catch {
|
||||||
Write-Error "Failed to create key: $($key.Key)"
|
Write-Error "Failed to import key: $path"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
foreach ($value in $key.Values) {
|
foreach ($value in $key.Values) {
|
||||||
try {
|
try {
|
||||||
Write-Debug "Importing value: $($value.Name):$($value.Value)"
|
#$newItem = New-ItemProperty -Path $key.Key -Name $value.Name -Value $value.Value -PropertyType 'String' -Force
|
||||||
#New-ItemProperty -Path $key.Key -Name $value.Name -Value $value.Value -PropertyType 'String' -Force
|
#Write-Information "Imported value: $newItem"
|
||||||
#Write-Host "Created registry value: $($value.Name) in $($key.Key)"
|
Write-Information "Imported value: $($value.Name) in $($key.Key)"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "Failed to create entry: $($value.Name) in $($key.Key)"
|
Write-Error "Failed to create entry: $($value.Name) in $($key.Key)"
|
||||||
@ -501,11 +487,39 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
'export' {
|
'export' {
|
||||||
Read-Registry -useRegFileFormat
|
|
||||||
}
|
|
||||||
'query' {
|
|
||||||
Read-Registry
|
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 {
|
default {
|
||||||
Write-Error "Unknown action: $action"
|
Write-Error "Unknown action: $action"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
BIN
ua/registry/uasrdev-add.reg
Normal file
BIN
ua/registry/uasrdev-add.reg
Normal file
Binary file not shown.
BIN
ua/registry/uasrdev-del.reg
Normal file
BIN
ua/registry/uasrdev-del.reg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user