Ask Your Question

Access the registry of the current user in windows

asked 2013-12-09 15:20:30 -0600

TwistedTech gravatar image

updated 2013-12-10 12:12:39 -0600

I have Windows 7 x64 machines that are running public facing applications under a limited user account. I would like to configure these machines using puppet but I have run into an issue. I need to configure the settings of specific user accounts but Puppet, by default, runs as the system account and does not have access to HKEY_Current_User. I can think of two workarounds for this:

  1. Run puppet as the current user. This would allow me to access all the current users settings but puppet would be a limited user and no longer have system level control.

  2. Write scripts ...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-12-13 14:23:50 -0600

TwistedTech gravatar image

updated 2014-01-09 14:42:34 -0600

To solve this I wrote a custom fact that returns the sids of the local accounts. I can then use the sid to access the registry through HKEY_USERS.

Here is my custom fact:

Facter.add("user_sid") do
  setcode do
    sids = {}
    user_list=Facter::Util::Resolution.exec('wmic useraccount where LocalAccount="True" get name,sid /format:csv')
    user_list = user_list.split
    user_list.each do |userline|
      node, username, sid = userline.split(',')
      sids[username] = sid

Then to convert it back to a hash in the manifest use:

# Change the => to : so the hash looks like json
$user_sid = regsubst($user_sid, '=>', ':', 'G')
$sids ...
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-12-09 15:20:30 -0600

Seen: 817 times

Last updated: Jan 09 '14