I can't read registry key with facter

690 views
Skip to first unread message

nicolas boquet

unread,
Jun 5, 2014, 11:07:39 AM6/5/14
to puppet...@googlegroups.com
Hello,
 
I've a problem with the module "facter/util/registry"...
 
i want to read key / value from registry. On windows x86, it's OK but in on windows x64, i've this error:
ERROR: The system was unable to find the specified registry key or value.
 
 
i 've create a fact to know the version of ocs inventory and the version of fusioninventory-agent:
this line work
Facter::Util::Registry.hklm_read('SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory Agent', 'DisplayVersion')
but this line doesn't work
Facter::Util::Registry.hklm_read('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent', 'DisplayVersion')
 
 
 
for exemple, in cmd.exe, i can do:
C:\Windows\System32\reg.exe export "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent" "C:\Uninstall.reg"
=> it's ok, i've my file uninstall.reg with my key FusionInventory-Agent
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent]
"DisplayName"="FusionInventory Agent 2.3.6 (x64 edition)"
"DisplayVersion"="2.3.6"
........
 
but with facter:
Facter::Util::Resolution.exec('C:\Windows\System32\reg.exe export "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory-Agent" "C:\Uninstall.reg"')
ERROR: The system was unable to find the specified registry key or value.
 
In fact, i want to know if it's possible with facter to read a 64 bit registry from facter...
 
Thank you and sorry for my english...

Rob Reynolds

unread,
Jun 5, 2014, 11:47:29 AM6/5/14
to puppet...@googlegroups.com
Nicolas,
 It is possible. Have a look at this recent write up I did - http://puppetlabs.com/blog/how-avoid-common-windows-gotchas-puppet (it even has a code example to do EXACTLY what you are asking). 


--
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/ae7676cb-94df-46d3-8c5e-e8e800abb940%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Rob Reynolds
Developer, Puppet Labs

Join us at PuppetConf 2014September 20-24 in San Francisco
Register by June 5th to take advantage of the Early Adopter discount save $349!

nicolas boquet

unread,
Jun 6, 2014, 4:55:40 AM6/6/14
to puppet...@googlegroups.com
Thank you , Thank you , Thank you  !!!
 
It's works.
 
I've create 2 functions in my fact
 
def key_exists?(path_reg)
  begin
    Win32::Registry::HKEY_LOCAL_MACHINE.open(path_reg, ::Win32::Registry::KEY_READ | 0x100 )
    return true
  rescue
    return false
  end
end
 
def readkey(path_reg,value)
  begin
    mykey = Win32::Registry.open(Win32::Registry::HKEY_LOCAL_MACHINE,path_reg,Win32::Registry::Constants::KEY_READ | 0x100)
    return mykey[value]
  rescue
    return false
  end
end
 
 
Reply all
Reply to author
Forward
0 new messages