Fix win_regedit module and tests. (#35478)

pull/35482/head
Matt Clay 7 years ago committed by Jordan Borean
parent 4da19f2d6b
commit e98e757ec4

@ -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 {

@ -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:

Loading…
Cancel
Save