1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
goto --Lua--
=goto;
io.stdout:seek("set",0)
--[[
This batch file will work if:
* The Lua interpreter is in the directory listed
in the %PATH% environment variable. Or in the
current directory.
* The Lua interpreter name is "lua.exe"
* Lua can search the required modules
]]
desc = [[
DESCRIPTION: searches the registry key and value name for a pattern
COMMAND: regsearch PATTERN [/l] [/u] [/subkey:path]
[/hkcu] [/hklm] [/hkcr] [/hku] [/hkcc]
PATTERN - Lua pattern
/l - convert to lower case before matching
/u - convert to upper case before matching
/hkcu - search HKEY_CURRENT_USER
/hkcu - search HKEY_CURRENT_USER
/hklm - search HKEY_LOCAL_MACHINE
/hkcr - search HKEY_CLASSES_ROOT
/hku - search HKEY_USERS
/hkcc - search HKEY_CURRENT_CONFIG
/hkall - same as /hkcc /hku /hkcr /hkcu /hklm
/subkey:path - e.g /subkey:Software\Microsoft
EXAMPLE: regsearch HKCU "[Mm][Rr][Uu]"
OUTPUTS: key or value name match
key match syntax is : ROOTKEY\Subkey\Key
value match syntax : ROOTKEY\Subkey\Key\\Value
REMARKS: write '%%' or '\37' for character '%'
to avoid environment expansion.
To redirect output to file use this syntax:
WinNT/Win9x: %comspec%/c regsearch [ROOTKEY] [PATTERN] > file.out
WinNT: %comspec%/q /c regsearch [ROOTKEY] [PATTERN] > file.out
WinNT: regsearch [ROOTKEY] [PATTERN] > file.out
]]
local tins = table.insert
local gmatch = string.gfind or string.gmatch
local opt = {}
local mpm = {['+']=true,['-']=false,['']=true}
for i,v in ipairs(arg) do
local k, d = gmatch(v, "/(%w+)%:(.+)$")()
if k and d then
opt[k] = d
else
k, d = gmatch(v, "/(%w+)([%-%+]?)$")()
if k then opt[k] = mpm[d] end
end
if not k then tins(opt, v) end
end
require"winreg"
local find = string.find
local gsub = string.gsub
local fmt = string.format
local lwr = string.lower
local upr = string.upper
local quot = function(s) return fmt("%q",s) end
local pats = {}
local rky0 = {hkcu=1,hklm=1,hkcr=1,hku=1,hkcc=1}
local rkys = {}
local case = opt.l and lwr or (opt.u and upr or function(x)return x end);
local skey = nil;
function regopen(xkey,k)
return xkey:openkey(k)
end
function joinkey(a,b)
return gsub(a, "(\\+)$", "")..'\\'..b
end
function regsrch(robj,rstr,pat)
if robj then
for v in robj:enumvalue() do
v = case(v)
if find(v,pat) then
print(rstr.."\\\\"..v)
end
end
for k in robj:enumkey() do
k = case(k)
local s = joinkey(rstr, k)
if find(k,pat) then
print(s)
end
local r, o = pcall(regopen, robj, k)
if r and o then regsrch(o,s, pat)
--else
-- print("CANT OPEN:",s)
end
collectgarbage()
end
end
end
local function main()
for i,v in ipairs(opt) do
tins(pats,v)
end
if opt.hkall then
for k,v in pairs(rky0) do
tins(rkys, upr(k))
end
else
for k,v in pairs(opt) do
if rky0[k] and v then
tins(rkys, upr(k))
end
end
end
if pats[1] then
if table.getn(rkys) < 1 then tins(rkys,"HKCU") end
skey = opt.subkey or ""
for _,key in ipairs(rkys) do
for _,pat in ipairs(pats) do
local x = joinkey(key, skey)
regsrch(winreg.openkey(x,'r'), case(x),pat)
end
end
else
print(desc)
end
end
ok, msg = pcall(main)
return ok or error(msg)
--[[
:--Lua--
@echo off
if "%OS%" == "Windows_NT" goto -winnt-
set f=%0
if exist "%f%" goto -run-
set f=%0.bat
if exist "%f%" goto -run-
for %%? in (%path%) do if exist "%%?\%0" set f=%%?\%0
if exist "%f%" goto -run-
for %%? in (%path%) do if exist "%%?\%0.bat" set f=%%?\%0.bat
:-run-
lua "%f%" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto -end-
:-winnt-
lua %~f0 %*
:-end-
::]]
|