1
0
Fork 0
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:
Matt Clay 2018-01-29 13:57:03 -08:00 committed by Jordan Borean
parent 4da19f2d6b
commit e98e757ec4
2 changed files with 42 additions and 19 deletions

View file

@ -448,7 +448,12 @@ try {
if (-not $check_mode) {
$reg_key = Get-Item -Path $path
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 {
Fail-Json $result "failed to change registry property '$name' at $($path): $($_.Exception.Message)"
} finally {
@ -476,7 +481,12 @@ $key_prefix[$path]
if (-not $check_mode) {
$reg_key = Get-Item -Path $path
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 {
Fail-Json $result "failed to change registry property '$name' at $($path): $($_.Exception.Message)"
} finally {
@ -525,7 +535,12 @@ $key_prefix[$path]
if (-not $check_mode) {
$reg_key = Get-Item -Path $path
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 {
Fail-Json $result "failed to delete registry property '$name' at $($path): $($_.Exception.Message)"
} finally {

View file

@ -469,13 +469,15 @@
- name: get result of create new key in loaded hive (check mode)
win_shell: |
$ErrorActionPreference = "Stop"
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
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)
assert:
that:
@ -491,13 +493,15 @@
- name: get result of create new key in loaded hive
win_shell: |
$ErrorActionPreference = "Stop"
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: new_key_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of create new key in loaded hive
assert:
that:
@ -533,12 +537,12 @@
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
$prop.Close()
}
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: new_prop_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of set hive key property (check mode)
assert:
that:
@ -561,12 +565,12 @@
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
$prop.Close()
}
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: new_prop_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of set hive key property
assert:
that:
@ -603,12 +607,12 @@
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
$prop.Close()
}
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: remove_prop_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of remove hive key property (check mode)
assert:
that:
@ -629,12 +633,12 @@
$prop = Get-ItemProperty -Path HKLM:\ANSIBLE\NewKey -Name TestProp -ErrorAction SilentlyContinue
if ($prop) {
$prop.TestProp
$prop.Close()
}
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: remove_prop_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of remove hive key property
assert:
that:
@ -665,13 +669,15 @@
- name: get result of remove key in loaded hive (check mode)
win_shell: |
$ErrorActionPreference = "Stop"
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: remove_key_in_hive_result_check
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of removekey in loaded hive (check mode)
assert:
that:
@ -688,13 +694,15 @@
- name: get result of remove key in loaded hive
win_shell: |
$ErrorActionPreference = "Stop"
&reg.exe load HKLM\ANSIBLE C:\Users\Default\NTUSER.dat > $null
Test-Path -Path HKLM:\ANSIBLE\NewKey
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
&reg.exe unload HKLM\ANSIBLE > $null
exit 0
register: remove_key_in_hive_result
- win_command: reg.exe unload HKLM\ANSIBLE
- name: assert result of remove key in loaded hive
assert:
that: