Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Registry: Set "Absent" with ValueData fails if Key uses "HKEY_LOCAL_MACHINE\..." #201

Open
dbaileyut opened this issue Jul 13, 2021 · 1 comment

Comments

@dbaileyut
Copy link

Details of the scenario you tried and the problem that is occurring

Trying to remove a registry value. I had been successfully creating Registry resources specifying the Keys in the "HKEY_LOCAL_MACHINE\*" format. However, when I switched to Ensure = 'Absent', it failed.

Verbose logs showing the problem

PowerShell DSC resource MSFT_RegistryResource failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find path 'C:\Windows\system32\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run' because it does not exist. + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : localhost

Suggested solution to the issue

Account for specifying keys in the HKEY_LOCAL_MACHINE format (which works for 'Present') in the code at:

if (-not [System.String]::IsNullOrEmpty($ValueName))
{
# If the user specified a registry key value with a name to remove, remove the registry key value with the specified name
$null = Remove-ItemProperty -Path $Key -Name $ValueName -Force
}

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Registry RemoveTeamsMachineAutoStart
{
    Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run'
    ValueName = 'Teams'
    ValueType = 'String'
    ValueData = '"C:\Program Files (x86)\Microsoft\Teams\current\Teams.exe"'
    Ensure = 'Absent'
    Force =  $true
}

The operating system the target node is running

OsName : Microsoft Windows 10 Enterprise for Virtual Desktops
OsOperatingSystemSKU : 175
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

Name Value


PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

2.12.0.0

@heinejeppesen
Copy link

Just ran into this, because I inadvertently had imported PSDscResources.
Not importing PSDscResources makes it work, as it then falls back to PSDesiredStateConfiguration.

It also works just writing 'HKLM:\Software...' instead of HKEY_LOCAL_MACHINE, so it utilizes the PSDrive for Cert:

Incase anyone else stumples upon this down the road.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants