Registry Key Read (code snippet)

Description

Fetches the value of a Windows Registry Key.

Requires: luacom

Returns

  • Value
  • err boolean (true if key not found, nil if found

Code

GetRegKey.fh_lua
function getRegKey(key)
    local sh = luacom.CreateObject "WScript.Shell"
    local ans 
    if pcall(function () ans = sh:RegRead(key) end) then
      return ans
    else
      return nil,true
    end
end

Usage

Checks for Evernote Install)

require "luacom"
    key,err = getRegKey('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Evernote.exe\\')
    if err then
       print('Reg Key Not Found')
       return
    else
       print('Reg Key = '..key)
    end