mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix win_regedit module and tests. (#35478)
This commit is contained in:
parent
4da19f2d6b
commit
e98e757ec4
2 changed files with 42 additions and 19 deletions
|
@ -448,7 +448,12 @@ try {
|
||||||
if (-not $check_mode) {
|
if (-not $check_mode) {
|
||||||
$reg_key = Get-Item -Path $path
|
$reg_key = Get-Item -Path $path
|
||||||
try {
|
try {
|
||||||
$reg_key.OpenSubKey($null, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree).SetValue($name, $data, $type)
|
$sub_key = $reg_key.OpenSubKey($null, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree)
|
||||||
|
try {
|
||||||
|
$sub_key.SetValue($name, $data, $type)
|
||||||
|
} finally {
|
||||||
|
$sub_key.Close()
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Fail-Json $result "failed to change registry property '$name' at $($path): $($_.Exception.Message)"
|
Fail-Json $result "failed to change registry property '$name' at $($path): $($_.Exception.Message)"
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -476,7 +481,12 @@ $key_prefix[$path]
|
||||||
if (-not $check_mode) {
|
if (-not $check_mode) {
|
||||||
$reg_key = Get-Item -Path $path
|
$reg_key = Get-Item -Path $path
|
||||||
try {
|
try {
|
||||||
$reg_key.OpenSubKey($null, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree).SetValue($name, $data, $type)
|
$sub_key = $reg_key.OpenSubKey($null, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree)
|
||||||
|
try {
|
||||||
|
$sub_key.SetValue($name, $data, $type)
|
||||||
|
} finally {
|
||||||
|
$sub_key.Close()
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Fail-Json $result "failed to change registry property '$name' at $($path): $($_.Exception.Message)"
|
Fail-Json $result "failed to change registry property '$name' at $($path): $($_.Exception.Message)"
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -525,7 +535,12 @@ $key_prefix[$path]
|
||||||
if (-not $check_mode) {
|
if (-not $check_mode) {
|
||||||
$reg_key = Get-Item -Path $path
|
$reg_key = Get-Item -Path $path
|
||||||
try {
|
try {
|
||||||
$reg_key.OpenSubKey($null, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree).DeleteValue($name)
|
$sub_key = $reg_key.OpenSubKey($null, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree)
|
||||||
|
try {
|
||||||
|
$sub_key.DeleteValue($name)
|
||||||
|
} finally {
|
||||||
|
$sub_key.Close()
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Fail-Json $result "failed to delete registry property '$name' at $($path): $($_.Exception.Message)"
|
Fail-Json $result "failed to delete registry property '$name' at $($path): $($_.Exception.Message)"
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -469,13 +469,15 @@
|
||||||
|
|
||||||
- name: get result of create new key in loaded hive (check mode)
|
- name: get result of create new key in loaded hive (check mode)
|
||||||
win_shell: |
|
win_shell: |
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
||||||
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
||||||
|
[GC]::Collect()
|
||||||
|
[GC]::WaitForPendingFinalizers()
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: new_key_in_hive_result_check
|
register: new_key_in_hive_result_check
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of create new key in loaded hive (check mode)
|
- name: assert result of create new key in loaded hive (check mode)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -491,13 +493,15 @@
|
||||||
|
|
||||||
- name: get result of create new key in loaded hive
|
- name: get result of create new key in loaded hive
|
||||||
win_shell: |
|
win_shell: |
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
||||||
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
||||||
|
[GC]::Collect()
|
||||||
|
[GC]::WaitForPendingFinalizers()
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: new_key_in_hive_result
|
register: new_key_in_hive_result
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of create new key in loaded hive
|
- name: assert result of create new key in loaded hive
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -533,12 +537,12 @@
|
||||||
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
||||||
if ($prop) {
|
if ($prop) {
|
||||||
$prop.TestProp
|
$prop.TestProp
|
||||||
|
$prop.Close()
|
||||||
}
|
}
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: new_prop_in_hive_result_check
|
register: new_prop_in_hive_result_check
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of set hive key property (check mode)
|
- name: assert result of set hive key property (check mode)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -561,12 +565,12 @@
|
||||||
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
||||||
if ($prop) {
|
if ($prop) {
|
||||||
$prop.TestProp
|
$prop.TestProp
|
||||||
|
$prop.Close()
|
||||||
}
|
}
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: new_prop_in_hive_result
|
register: new_prop_in_hive_result
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of set hive key property
|
- name: assert result of set hive key property
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -603,12 +607,12 @@
|
||||||
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
||||||
if ($prop) {
|
if ($prop) {
|
||||||
$prop.TestProp
|
$prop.TestProp
|
||||||
|
$prop.Close()
|
||||||
}
|
}
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: remove_prop_in_hive_result_check
|
register: remove_prop_in_hive_result_check
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of remove hive key property (check mode)
|
- name: assert result of remove hive key property (check mode)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -629,12 +633,12 @@
|
||||||
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
|
||||||
if ($prop) {
|
if ($prop) {
|
||||||
$prop.TestProp
|
$prop.TestProp
|
||||||
|
$prop.Close()
|
||||||
}
|
}
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: remove_prop_in_hive_result
|
register: remove_prop_in_hive_result
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of remove hive key property
|
- name: assert result of remove hive key property
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -665,13 +669,15 @@
|
||||||
|
|
||||||
- name: get result of remove key in loaded hive (check mode)
|
- name: get result of remove key in loaded hive (check mode)
|
||||||
win_shell: |
|
win_shell: |
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
||||||
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
||||||
|
[GC]::Collect()
|
||||||
|
[GC]::WaitForPendingFinalizers()
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: remove_key_in_hive_result_check
|
register: remove_key_in_hive_result_check
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of removekey in loaded hive (check mode)
|
- name: assert result of removekey in loaded hive (check mode)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -688,13 +694,15 @@
|
||||||
|
|
||||||
- name: get result of remove key in loaded hive
|
- name: get result of remove key in loaded hive
|
||||||
win_shell: |
|
win_shell: |
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
®.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
|
||||||
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
Test-Path -Path HKLM:\ANSIBLE\NewKey
|
||||||
|
[GC]::Collect()
|
||||||
|
[GC]::WaitForPendingFinalizers()
|
||||||
|
®.exe unload HKLM\ANSIBLE > $null
|
||||||
exit 0
|
exit 0
|
||||||
register: remove_key_in_hive_result
|
register: remove_key_in_hive_result
|
||||||
|
|
||||||
- win_command: reg.exe unload HKLM\ANSIBLE
|
|
||||||
|
|
||||||
- name: assert result of remove key in loaded hive
|
- name: assert result of remove key in loaded hive
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
|
Loading…
Add table
Reference in a new issue