Changing registry values with Win32::Registry

C

Collin Miller

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?
 
J

Jano Svitok

T24gNi8xNC8wNywgQ29sbGluIE1pbGxlciA8Y29sbGludG1pbGxlckBnbWFpbC5jb20+IHdyb3Rl
Ogo+IEknbSB0cnlpbmcgdG8gY2hhbmdlIGEgcmVnaXN0cnkgdmFsdWUgZm9yIGFuIElQVFYgU0RL
Cj4KPiBUaGlzIGNvZGU6Cj4KPiBXaW4zMjo6UmVnaXN0cnk6OkhLRVlfTE9DQUxfTUFDSElORS5v
cGVuKCJTT0ZUV0FSRVxcUEFUSF9UT19LRVlcCj4gXCIpLndyaXRlKCJJZ25vcmVUaW55SUZyYW1l
cyIsV2luMzI6OlJlZ2lzdHJ5OjpSRUdfRFdPUkQsMCkKPgo+IFJldHVybnMgdGhpcyBlcnJvcjoK
Pgo+IFdpbjMyOjpSZWdpc3RyeTo6RXJyb3I6IEFjY2VzcyBpcyBkZW5pZWQuCj4gICAgICAgICBm
cm9tIGM6L3J1YnkvbGliL3J1YnkvMS44L3dpbjMyL3JlZ2lzdHJ5LnJiOjc0MzppbiBgd3JpdGUn
Cj4gICAgICAgICBmcm9tIChpcmIpOjE1MAo+ICAgICAgICAgZnJvbSCivjowCj4KPiBBbnlib2R5
IGtub3cgaG93IEkgY2FuIGVuc3VyZSBhY2Nlc3MgdG8gdGhpcyBrZXk/Cgp1c2UgV2luMzI6OlJl
Z2lzdHJ5OjpLRVlfV1JJVEUgb3IgYW5vdGhlciBLRVlfKiBhY2Nlc3Mgc3BlY2lmaWVyIGFzCnRo
ZSBuZXh0IHBhcmFtZXRlcjoKCldpbjMyOjpSZWdpc3RyeTo6SEtFWV9MT0NBTF9NQUNISU5FLm9w
ZW4oIlNPRlRXQVJFXFxQQVRIX1RPX0tFWVxcIixXaW4zMjo6UmVnaXN0cnk6OktFWV9XUklURSku
d3JpdGUoIklnbm9yZVRpbnlJRnJhbWVzIixXaW4zMjo6UmVnaXN0cnk6OlJFR19EV09SRCwwKQoK
Si4K
 
N

Navaneet Kumar

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
 
J

Jesús Gabriel y Galán

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

Ex:
Win32::Registry::HKEY_LOCAL_MACHINE.open(REG_PATH_1,Win32::Registry::Cons= tants::KEY_ALL_ACCESS)
do |reg|
=A0 =A0if (reg.read_i(name)!=3D"")
=A0 =A0 =A0 =A0 =A0 =A0 =A0return reg.read_i(name)
=A0 =A0 =A0 =A0 =A0 =A0end
=A0 =A0end

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 =3D reg.read_i(name)).nil?
return key
end

Jesus.
 
N

Navaneet Kumar

Jesús Gabriel y Galán said:
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.
 
J

Jesús Gabriel y Galán

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.

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

key =3D reg.read_i(name)
p key

Jesus.
 
H

Heesob Park

Hi,

2010/7/8 Navaneet Kumar said:
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.
You can handle it like this:

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


Regards,

Park Heesob
 
N

Navaneet Kumar

Heesob said:
Hi,


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 Heesob

Thanks Park...

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

Michal Suchanek

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top