working with the registry

T

Thufir

I found:

require 'win32/registry'
keyname = 'SYSTEM\CurrentControlSet\Control\Session Manager
\Environment'
access = Win32::Registry::KEY_ALL_ACCESS
Win32::Registry::HKEY_LOCAL_MACHINE.open(keyname, access) do |reg|
# Add to path
['c:\foo\bin', 'c:\bar\bin'].each do |directory|
unless (reg['path'].include? directory)
reg['path'] += ';' + directory
end
end
# Add environment variable
reg['foobar'] = '42'
# Note: won't take effect until restart!
end

<http://multipart-mixed.com/downloads/software/
spectra_d500_lessons_learned.pdf>


but would like to query the registry from ruby. Just thinking outloud
here, haven't found a tutorial invovling the registry and ruby which I
find useful yet :(


C:\msi>
C:\msi>
C:\msi>dir
Volume in drive C has no label.
Volume Serial Number is 0491-510F


Directory of C:\msi


12/06/2007 12:36 PM <DIR> .
12/06/2007 12:36 PM <DIR> ..
12/06/2007 12:25 PM 10,970,624 python-2.5.1.msi
1 File(s) 10,970,624 bytes
2 Dir(s) 28,396,879,872 bytes free


C:\msi>
C:\msi>reg query HKEY_LOCAL_MACHINE\Software\Policies\Microsoft
\Windows
\Installe
r


! REG.EXE VERSION 3.0


HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer
EnableAdminTSRemote REG_DWORD 0x1


C:\msi>
C:\msi>reg query HKEY_CURRENT_USER\Software\Policies\Microsoft
\Windows
\


! REG.EXE VERSION 3.0


HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\


HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\\Control Panel


HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\\System


C:\msi>



thanks,

Thufir
 
Y

yermej

but would like to query the registry from ruby. Just thinking outloud
here, haven't found a tutorial invovling the registry and ruby which I
find useful yet :(

The following is what I was able to figure out from the standard
library API docs at http://www.ruby-doc.org/stdlib/. It's pretty
Rubyish once you get going.

[in irb]
irb> require 'win32/registry'
irb> include Win32

irb> Registry.open(Registry::HKEY_LOCAL_MACHINE, 'Software\Policies
\Microsoft\Windows\Installer').each_value do |subkey, type, data|
irb* puts "#{subkey} (#{type}): #{data}"
irb> end

The only problem I see with this is that you get the constant value
for type (4 in this case) rather than the constant name (REG_DWORD).
Is that what you were wanting to do?

I don't have this key on my machine. Only HKEY_CURRENT_USER\Software
\Policies\Microsoft\SystemCertificates which has subkeys, but no
values, but all keys should be similar to the above.
 
T

Thufir

I would like to use:

each_value() {|subkey, type, data| ...}

iterator

[Source]

# File Win32API/lib/win32/registry.rb, line 624
def each_value
index = 0
while true
begin
subkey = API.EnumValue(@hkey, index)
rescue Error
break
end
begin
type, data = read(subkey)
rescue Error
next
end
yield subkey, type, data
index += 1
end
index
end

<http://www.ruby-doc.org/stdlib/libdoc/Win32API/rdoc/classes/Win32/
Registry.html>



here's what I have:


irb(main):040:3*
irb(main):041:3*
puts.each_key(Registry.open(Registry::HKEY_LOCAL_MACHINE, 'Software
\Policies\'))
irb(main):042:5' '
irb(main):043:5>
irb(main):044:5*


But I seem to be having some sort of problem with closing quotes
(syntax). Can I do that with the puts method?



thanks,

Thufir
 
P

Phrogz

here's what I have:

irb(main):040:3*
irb(main):041:3*
puts.each_key(Registry.open(Registry::HKEY_LOCAL_MACHINE, 'Software
\Policies\'))
irb(main):042:5' '
irb(main):043:5>
irb(main):044:5*

But I seem to be having some sort of problem with closing quotes
(syntax).

nickname = 'Gavin \'Phrogz\' Kistner'

The backslashes are escaping your last quote. Instead try:
'Software\\Policies\\'
(use a backslash to escape the backslash)
 

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,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top