registry workaround for HKCU(HKEY_CURRENT_USER)

690 views
Skip to first unread message

bkmr...@gmail.com

unread,
Sep 13, 2016, 4:36:24 PM9/13/16
to Puppet Users
hello all,

I am trying to find a workaround as to how one would set some registry entry for HKCU using the registry module, as looking at the limitations it states below(so HKCU is not supported)

"Keys within HKEY_LOCAL_MACHINE (hklm) or HKEY_CLASSES_ROOT (hkcr) are supported. Other predefined root keys (e.g., HKEY_USERS) are not currently supported."

i tried creating the below class, just for the heck of it to see if it even works or not...but of course it does not, i get "Unsupported predefined key"
class reg_entry {
    registry::value { 'VisualFXSetting':
    key  => 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects',
    type   => dword,
    data => '1',
  }
}

i get the following error when i try to test it out using above class

Error: Failed to apply catalog: Parameter path failed on Registry_key[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects]: Munging failed for
 value "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VisualEffects" in class path: Unsupported predefined key: HKCU\Software\Microsoft\Windows\
CurrentVersion\Explorer\VisualEffects at /etc/puppetlabs/code/environments/production/modules/registry/manifests/value.pp:67

so i wanted to find out what are other folks doing with regards to setting HKCU keys...i suppose i can use "exec" with powershell to accomplish this but how do i set the path for HKCU in the mainfest, below does not work and i get error "Unrecognized escape sequence"...

$path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects\"
$command = "(set-ItemProperty -Path $path -Name "VisualFXSetting" -Value "1")"

Peter Kristolaitis

unread,
Sep 13, 2016, 4:46:06 PM9/13/16
to puppet...@googlegroups.com

Since HKCU is contextualized to the current user, and the Puppet agent generally runs as SYSTEM, this is almost guaranteed not to do what you want if you can even get it to work.  You will likely have to write PowerShell that knows how to change context to another user to accomplish useful things within HKCU.

To solve the errors in your PowerShell example, you will have to escape the slashes, e.g.

$path = "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VisualEffects\\"
$command = "(set-ItemProperty -Path $path -Name "VisualFXSetting" -Value "1")"

However, as mentioned above, this alone probably won't do what you want / expect, because Puppet is executing in the incorrect user context.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0c68b9b3-761e-4444-89d5-e3de60aa4ee8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages