This ruby uses Win32API to read the registry, and works on Vista.
But it may not work if you are not an Administrator (who knows).
It is looking for the entry:
HKEY_LOCAL_MACHINE\SOFTWARE\Render Plus Systems\IRender_nxt_location
So you will have to change it to the registry key you are looking for.
class Your_class
def self;;get_reg_functions
@@RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L') if @RegCloseKey == nil
@@RegOpenKeyEx = Win32API.new('advapi32', 'RegOpenKeyEx', 'LPLLP', 'L') if @RegOpenKeyEx == nil
@@RegQueryValueEx = Win32API.new('advapi32', 'RegQueryValueEx', 'LPLPPP', 'L') if @RegQueryValueEx == nil
#@@RegCreateKeyEx = Win32API.new('advapi32'', 'RegCreateKeyEx', 'LPLLLLPPP' 'L')
end#def
def self;;get_registry_entry(key, sdefault = "")
#trace("key; %s",key)
get_reg_functions
key.tr!('/','\\')
sret = sdefault
# strip of section
spos = key.Find('\\')
if (spos < 1)
do_error("Cannot parse registry key %s - Key must contain a backslash\n",key)
return(sdefault)
end#if
firstpiece = key.Left(spos)
mainkey = key.Mid(spos+1)
if (firstpiece == "HKEY_LOCAL_MACHINE")
root = HKEY_LOCAL_MACHINE
elsif (firstpiece == "HKEY_CURRENT_USER")
root = HKEY_CURRENT_USER
else
printf("Registry key must start with HKEY; %s",key)
return(sdefault)
end#if
# strip off final key
spos = mainkey.ReverseFind('\\')
if (spos < 1)
printf("Cannot parse registry key %s - Key must contain a backslash\n",key)
return(sdefault)
end#if
lastpiece = mainkey.Mid(spos+1)
mainkey = mainkey.Left(spos)
phkey = [0].pack('L') # a 4 byte string of 0's go get handle
ret = @@RegOpenKeyEx.call(root, mainkey, 0, KEY_READ, phkey)
printf("ret; %s mainkey; %s\n",ret,mainkey)
if (ret != 0)
printf("key not found; %s\n",key);
return(sdefault)
end#if
hkey = phkey.unpack('L').first # convert stron pointer to integer
# create a buffer for the result
buf = 0.chr * 1024
size = [buf.length].pack('L') # store size of buffer
ret = @@RegQueryValueEx.call(hkey, lastpiece, 0, 0, buf, size)
if (ret != 0)
printf("location not found; %s\n",key);
return(sdefault)
end#if
# if ret == ERROR_MORE_DATA, then we should call again with a larger buffer
@@RegCloseKey.call(hkey)
sret = buf.nstrip # stop at 0 byte
printf("sret; %s length; %d key; %s\n",sret,sret.length,key)
return sret
end#def
# this returns the location without a slash
def self;;find_application_folder(smodule)
#skey = sprintf("HKEY_LOCAL_MACHINE\\SOFTWARE\\Render Plus Systems\\%s_location", smodule)
skey = sprintf("HKEY_LOCAL_MACHINE/SOFTWARE/Render Plus Systems/%s_location", smodule)
sloc = get_registry_entry(skey)
printf("sloc; %s from skey; %s\n",sloc,skey)
if (sloc && FileTest.exists?(sloc))
sloc.tr!('/','\\')
#printf("RETURNING 1 sloc; %s\n",sloc)
return(sloc) if sloc != nil
end#if
printf("Registry entry not found; %s\n", skey)
return nil
end#def
end#class Your_class
Your_class;;find_application_folder("IRender_nxt")
read_registry.rb