Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Changing registry values with Win32::Registry

Reply
Thread Tools

Changing registry values with Win32::Registry

 
 
Collin Miller
Guest
Posts: n/a
 
      06-14-2007
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?

 
Reply With Quote
 
 
 
 
Jano Svitok
Guest
Posts: n/a
 
      06-15-2007
T24gNi8xNC8wNywgQ29sbGluIE1pbGxlciA8Y29sbGludG1pbG xlckBnbWFpbC5jb20+IHdyb3Rl
Ogo+IEknbSB0cnlpbmcgdG8gY2hhbmdlIGEgcmVnaXN0cnkgdm FsdWUgZm9yIGFuIElQVFYgU0RL
Cj4KPiBUaGlzIGNvZGU6Cj4KPiBXaW4zMjo6UmVnaXN0cnk6Ok hLRVlfTE9DQUxfTUFDSElORS5v
cGVuKCJTT0ZUV0FSRVxcUEFUSF9UT19LRVlcCj4gXCIpLndyaX RlKCJJZ25vcmVUaW55SUZyYW1l
cyIsV2luMzI6OlJlZ2lzdHJ5OjpSRUdfRFdPUkQsMCkKPgo+IF JldHVybnMgdGhpcyBlcnJvcjoK
Pgo+IFdpbjMyOjpSZWdpc3RyeTo6RXJyb3I6IEFjY2VzcyBpcy BkZW5pZWQuCj4gICAgICAgICBm
cm9tIGM6L3J1YnkvbGliL3J1YnkvMS44L3dpbjMyL3JlZ2lzdH J5LnJiOjc0MzppbiBgd3JpdGUn
Cj4gICAgICAgICBmcm9tIChpcmIpOjE1MAo+ICAgICAgICAgZn JvbSCivjowCj4KPiBBbnlib2R5
IGtub3cgaG93IEkgY2FuIGVuc3VyZSBhY2Nlc3MgdG8gdGhpcy BrZXk/Cgp1c2UgV2luMzI6OlJl
Z2lzdHJ5OjpLRVlfV1JJVEUgb3IgYW5vdGhlciBLRVlfKiBhY2 Nlc3Mgc3BlY2lmaWVyIGFzCnRo
ZSBuZXh0IHBhcmFtZXRlcjoKCldpbjMyOjpSZWdpc3RyeTo6SE tFWV9MT0NBTF9NQUNISU5FLm9w
ZW4oIlNPRlRXQVJFXFxQQVRIX1RPX0tFWVxcIixXaW4zMjo6Um VnaXN0cnk6OktFWV9XUklURSku
d3JpdGUoIklnbm9yZVRpbnlJRnJhbWVzIixXaW4zMjo6UmVnaX N0cnk6OlJFR19EV09SRCwwKQoK
Si4K

 
Reply With Quote
 
 
 
 
dima
Guest
Posts: n/a
 
      06-15-2007
On Jun 15, 9:51 am, "Jano Svitok" <(E-Mail Removed)> wrote:
> On 6/14/07, Collin Miller <(E-Mail Removed)> wrote:
>
> > 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?

>
> 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.


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

 
Reply With Quote
 
Navaneet Kumar
Guest
Posts: n/a
 
      07-08-2010
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Jess Gabriel y Galn
Guest
Posts: n/a
 
      07-08-2010
On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <(E-Mail Removed)> wrot=
e:
> 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.

 
Reply With Quote
 
Navaneet Kumar
Guest
Posts: n/a
 
      07-08-2010
Jesús Gabriel y Galán wrote:
> On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <(E-Mail Removed)>
> 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.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Jess Gabriel y Galn
Guest
Posts: n/a
 
      07-08-2010
On Thu, Jul 8, 2010 at 11:45 AM, Navaneet Kumar <(E-Mail Removed)> wrot=
e:
> Jes=C3=BAs Gabriel y Gal=C3=A1n wrote:
>> On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <(E-Mail Removed)>
>> wrote:
>>> =EF=BF=BD =EF=BF=BDend
>>>
>>> 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?
>> =C2=A0 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.


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.

 
Reply With Quote
 
Heesob Park
Guest
Posts: n/a
 
      07-08-2010
Hi,

2010/7/8 Navaneet Kumar <(E-Mail Removed)>:
> Jes=C3=BAs Gabriel y Gal=C3=A1n wrote:
>> On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <(E-Mail Removed)>
>> wrote:
>>> =EF=BF=BD =EF=BF=BDend
>>>
>>> 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?
>> =C2=A0 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.
>

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

 
Reply With Quote
 
Navaneet Kumar
Guest
Posts: n/a
 
      07-08-2010
Heesob Park wrote:
> Hi,
>
> 2010/7/8 Navaneet Kumar <(E-Mail Removed)>:
>>> 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 Heesob


Thanks Park...

I was trying the same and it works for me. Is is possible to handle
without handling the exception?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Michal Suchanek
Guest
Posts: n/a
 
      07-08-2010
On 8 July 2010 12:37, Navaneet Kumar <(E-Mail Removed)> wrote:
> Heesob Park wrote:
>> Hi,
>>
>> 2010/7/8 Navaneet Kumar <(E-Mail Removed)>:
>>>> 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:
>>
>> =C2=A0 begin
>> =C2=A0 if (reg.read_i(name)!=3D"")
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return reg.read_i(name)
>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
>> =C2=A0 rescue Win32::Registry::Error =3D> e
>> =C2=A0 if e.code =3D=3D 2
>> =C2=A0 =C2=A0 puts "#{name} key not exist!"
>> =C2=A0 end
>> =C2=A0 end
>>
>>
>> Regards,
>>
>> Park Heesob

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help:win95 registry vs. winxp registry wege Computer Support 3 06-09-2006 06:28 PM
How to read a registry key from Windows registry ? Leny Java 3 02-01-2005 07:54 AM
Interpretation of registry log of tweakui produced registry alteration vincemoon@rcn.com ASP .Net 0 01-10-2005 02:53 AM
Reading registry key throws "Requested registry access is not allowed." HK ASP .Net 1 04-01-2004 04:44 PM



Advertisments