ruby registry checking
registry, ruby, windows
Solution
I figured it out - http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
reg_type = Win32::Registry::KEY_READ | 0x100
This solved the issue! My guess is that you guys were not testing on x64?
Problem
I have the following snippet which I am trying to use to validate registry keys (OS is Windows 2008R2 or Win7) ``` def value_exists?(path,key) reg_type = Win32::Registry::KEY_READ Win32::Registry::HKEY_LOCAL_MACHINE.open(path, reg_type) do |reg| begin regkey = reg[key] return true rescue return false end end end ``` When I do the following 2 commands the output is expected (in my case false is returned) : ``` puts(value_exists?("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\",'PendingFileRenameOperations')) puts(value_exists?("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\",'RebootPending')) ``` When I perform a ``` puts(value_exists?("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\",'RebootRequired')) ``` I get the following error ``` C:/Ruby187/lib/ruby/1.8/win32/registry.rb:528:in `open': The system cannot find the file specified. (Win32::Registry::Error) from C:/Ruby187/lib/ruby/1.8/win32/registry.rb:608:in `open' from ./reg2.rb:7:in `value_exists?' from ./reg2.rb:21 ``` I don't really understand what to do to make this work. I suspect it might have something to do with the systems being x64 and it failing to find the key in the right location. but I am not sure what I need to do to remedy this. Thanks for your help in advance!