Changing registry values with Win32::Registry

I’m trying to change a registry value for an IPTV SDK

This code:

Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\PATH_TO_KEY
").write(“IgnoreTinyIFrames”,Win32::Registry::REG_DWORD,0)

Returns this error:

Win32::Registry::Error: Access is denied.
from c:/ruby/lib/ruby/1.8/win32/registry.rb:743:in `write’
from (irb):150
from ♥:0

Anybody know how I can ensure access to this key?

On 6/14/07, Collin M. [email protected] wrote:

    from c:/ruby/lib/ruby/1.8/win32/registry.rb:743:in `write'
    from (irb):150
    from ¢¾:0

Anybody know how I can ensure access to this key?

use Win32::Registry::KEY_WRITE or another KEY_* access specifier as
the next parameter:

Win32::Registry::HKEY_LOCAL_MACHINE.open(“SOFTWARE\PATH_TO_KEY\”,Win32::Registry::KEY_WRITE).write(“IgnoreTinyIFrames”,Win32::Registry::REG_DWORD,0)

J.

On Jun 15, 9:51 am, “Jano S.” [email protected] wrote:

Win32::Registry::HKEY_LOCAL_MACHINE.open(“SOFTWARE\PATH_TO_KEY\”,Win32::Registry::KEY_WRITE).write(“IgnoreTinyIFrames”,Win32::Registry::REG_DWORD,0)

J.

Look at https://www.ruby-forum.com/topic/76585

How do we handle null value from opened HKEY instance. if
(reg.read_i(name)!="") in below line I have tried but it doesn’t work
properly.

Ex:
Win32::Registry::HKEY_LOCAL_MACHINE.open(REG_PATH_1,Win32::Registry::Constants::KEY_ALL_ACCESS)
do |reg|
if (reg.read_i(name)!="")
return reg.read_i(name)
end
end

I need another instance to open for different REG_PATH. The reason
behind that is if the reg key is in first path then return the value
other wise open the key to read the reg key from different path.

Thanks

On Thu, Jul 8, 2010 at 10:52 AM, Navaneet K. [email protected]
wrote:

end

I need another instance to open for different REG_PATH. The reason
behind that is if the reg key is in first path then return the value
other wise open the key to read the reg key from different path.

I have no idea about that API, but if read_i is returning nil for
non-existing keys, you can try this:

unless (key = reg.read_i(name)).nil?
return key
end

Jesus.

Jesús Gabriel y Galán wrote:

On Thu, Jul 8, 2010 at 10:52 AM, Navaneet K. [email protected]
wrote:

� �end

I need another instance to open for different REG_PATH. The reason
behind that is if the reg key is in first path then return the value
other wise open the key to read the reg key from different path.

I have no idea about that API, but if read_i is returning nil for
non-existing keys, you can try this:

unless (key = reg.read_i(name)).nil?
return key
end

Jesus.

Thanks for your reply.

Just clarification, The specified key is not exist not the value is
having null. I mean the ‘name’ key is not exist in that path. How do we
handle this in ruby.

On Thu, Jul 8, 2010 at 11:45 AM, Navaneet K. [email protected]
wrote:

non-existing keys, you can try this:
having null. I mean the ‘name’ key is not exist in that path. How do we
handle this in ruby.

I don’t know what the API returns in that instance. Can you try this
and show us?

key = reg.read_i(name)
p key

Jesus.

Hi,

2010/7/8 Navaneet K. [email protected]:

non-existing keys, you can try this:
having null. I mean the ‘name’ key is not exist in that path. How do we
handle this in ruby.

You can handle it like this:

begin
if (reg.read_i(name)!=“”)
return reg.read_i(name)
end
rescue Win32::Registry::Error => e
if e.code == 2
puts “#{name} key not exist!”
end
end

Regards,

Park H.

Thank you

On 8 July 2010 12:37, Navaneet K. [email protected] wrote:

 begin
Regards,

Park H.

Thanks Park…

I would do something like

reg.read_i(name) rescue nil

unless I wanted to know exactly what went wrong.

I wrote some hacks for replacing key values in registry so I can dig
them up if you want.

HTH

Michal

Heesob P. wrote:

Hi,

2010/7/8 Navaneet K. [email protected]:

non-existing keys, you can try this:
having null. I mean the ‘name’ key is not exist in that path. How do we
handle this in ruby.

You can handle it like this:

begin
if (reg.read_i(name)!=“”)
return reg.read_i(name)
end
rescue Win32::Registry::Error => e
if e.code == 2
puts “#{name} key not exist!”
end
end

Regards,

Park H.

Thanks Park…

I was trying the same and it works for me. Is is possible to handle
without handling the exception?

Win32::Registry::Error: Access is denied.
from c:/ruby/lib/ruby/1.8/win32/registry.rb:743:in `write’
from (irb):150
from ♥:0

Anybody know how I can ensure access to this key?

This might help:

http://wiki.github.com/rdp/ruby_tutorials_core/win32registry