From: Navaneet Kumar on
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/.

From: Jesús Gabriel y Galán on
On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <tonavaneet(a)gmail.com> wrote:
> 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.

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.

From: Navaneet Kumar on
Jesús Gabriel y Galán wrote:
> On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <tonavaneet(a)gmail.com>
> 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/.

From: Jesús Gabriel y Galán on
On Thu, Jul 8, 2010 at 11:45 AM, Navaneet Kumar <tonavaneet(a)gmail.com> wrote:
> Jesús Gabriel y Galán wrote:
>> On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <tonavaneet(a)gmail.com>
>> 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.

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.

From: Heesob Park on
Hi,

2010/7/8 Navaneet Kumar <tonavaneet(a)gmail.com>:
> Jesús Gabriel y Galán wrote:
>> On Thu, Jul 8, 2010 at 10:52 AM, Navaneet Kumar <tonavaneet(a)gmail.com>
>> 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.
>
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