Windows Registry

lua-users home
wiki

A preliminary Windows Registry API. Working code is available [here], licensed under the [MIT license]. Email MarkEdgar for questions or comments.

Example usage is as follows, and this constitutes the only documentation:

require "windows.reg"

--[[
Obtain keys simply by indexing the windows.reg namespace.
The toplevel keys are:
    HKCR, HKEY_CLASSES_ROOT,
    HKCC, HKEY_CURRENT_CONFIG,
    HKCU, HKEY_CURRENT_USER,
    HKLM, HKEY_LOCAL_MACHINE,
    HKU, HKEY_USERS,
--]]
local key1 = windows.reg.HKLM.Software.Sample
local key2 = windows.reg.HKEY_LOCAL_MACHINE.Software
local key3 = key2.Sample

key1:exists() -- check if key exists
key1:create() -- create key
key1:delete() -- delete key

-- iterate over subkey names
for keyname in key1:subkeys() do
    print(keyname)
end

-- iterate over value names
for valuename in key1:values() do
    print(valuename)
end

-- iterate over values (value names and data)
for valuename, valuedata in key1:values(true) do
    print(valuename, valuedata)
end

print(key1"version") -- query value
key1{version = "20050314T205100"} -- create REG_SZ value
key1:delete("version") -- delete value

key1{path = windows.reg.expand_sz("%windir%\\Lua")} -- create REG_EXPAND_SZ value
key1"path" -- returns "C:\\WINDOWS\\Lua"
local v = key1{"path"} -- get valuedata object
v.type -- returns reg.expand_sz
v.data -- returns "%windir%\\Lua"

--[[ keys
windows.reg.HKCR, windows.reg.HKEY_CLASSES_ROOT
windows.reg.HKCC, windows.reg.HKEY_CURRENT_CONFIG
windows.reg.HKCU, windows.reg.HKEY_CURRENT_USER
windows.reg.HKLM, windows.reg.HKEY_LOCAL_MACHINE
windows.reg.HKU, windows.reg.HKEY_USERS
--]]

--[[ values
reg.dword(num)
reg.qword(num)
reg.string(str)
reg.expand_sz(str)
reg.multi_sz(str1, ...)
reg.binary(str)
reg.binary(hex(str))
reg.type(4, ...)
--]]

--[[ auxiliar
reg.import(filename)
reg.export(key1.HKLM["Software\\Sample"], filename)
--]]

RecentChanges · preferences
edit · history
Last edited March 19, 2008 7:39 pm GMT (diff)