Module: Win32::Registry::API
- Extended by:
- Fiddle::Importer
- Includes:
- Constants
- Defined in:
- lib/win32/registry.rb
Overview
Constant Summary
Constants included
from Constants
Constants::HKEY_CLASSES_ROOT, Constants::HKEY_CURRENT_CONFIG, Constants::HKEY_CURRENT_USER, Constants::HKEY_DYN_DATA, Constants::HKEY_LOCAL_MACHINE, Constants::HKEY_PERFORMANCE_DATA, Constants::HKEY_PERFORMANCE_NLSTEXT, Constants::HKEY_PERFORMANCE_TEXT, Constants::HKEY_USERS, Constants::KEY_ALL_ACCESS, Constants::KEY_CREATE_LINK, Constants::KEY_CREATE_SUB_KEY, Constants::KEY_ENUMERATE_SUB_KEYS, Constants::KEY_EXECUTE, Constants::KEY_NOTIFY, Constants::KEY_QUERY_VALUE, Constants::KEY_READ, Constants::KEY_SET_VALUE, Constants::KEY_WRITE, Constants::MAX_KEY_LENGTH, Constants::MAX_VALUE_LENGTH, Constants::REG_BINARY, Constants::REG_CREATED_NEW_KEY, Constants::REG_DWORD, Constants::REG_DWORD_BIG_ENDIAN, Constants::REG_DWORD_LITTLE_ENDIAN, Constants::REG_EXPAND_SZ, Constants::REG_FORCE_RESTORE, Constants::REG_FULL_RESOURCE_DESCRIPTOR, Constants::REG_LEGAL_OPTION, Constants::REG_LINK, Constants::REG_MULTI_SZ, Constants::REG_NONE, Constants::REG_NO_LAZY_FLUSH, Constants::REG_OPENED_EXISTING_KEY, Constants::REG_OPTION_BACKUP_RESTORE, Constants::REG_OPTION_CREATE_LINK, Constants::REG_OPTION_NON_VOLATILE, Constants::REG_OPTION_OPEN_LINK, Constants::REG_OPTION_RESERVED, Constants::REG_OPTION_VOLATILE, Constants::REG_QWORD, Constants::REG_QWORD_LITTLE_ENDIAN, Constants::REG_REFRESH_HIVE, Constants::REG_RESOURCE_LIST, Constants::REG_RESOURCE_REQUIREMENTS_LIST, Constants::REG_SZ, Constants::REG_WHOLE_HIVE_VOLATILE, Constants::STANDARD_RIGHTS_READ, Constants::STANDARD_RIGHTS_WRITE
Class Method Summary
collapse
-
.check(result) ⇒ Object
-
.CloseKey(hkey) ⇒ Object
-
.CreateKey(hkey, name, opt, desired) ⇒ Object
-
.DeleteKey(hkey, name) ⇒ Object
-
.DeleteValue(hkey, name) ⇒ Object
-
.EnumKey(hkey, index) ⇒ Object
-
.EnumValue(hkey, index) ⇒ Object
-
.FlushKey(hkey) ⇒ Object
-
.make_wstr(str) ⇒ Object
-
.OpenKey(hkey, name, opt, desired) ⇒ Object
-
.packdw(dw) ⇒ Object
-
.packhandle(h) ⇒ Object
-
.packqw(qw) ⇒ Object
-
.QueryInfoKey(hkey) ⇒ Object
-
.QueryValue(hkey, name) ⇒ Object
-
.SetValue(hkey, name, type, data, size) ⇒ Object
-
.unpackdw(dw) ⇒ Object
-
.unpackhandle(h) ⇒ Object
-
.unpackqw(qw) ⇒ Object
-
.win64? ⇒ Boolean
Class Method Details
.check(result) ⇒ Object
249
250
251
|
# File 'lib/win32/registry.rb', line 249
def check(result)
raise Error, result, caller(1) if result != 0
end
|
.CloseKey(hkey) ⇒ Object
347
348
349
|
# File 'lib/win32/registry.rb', line 347
def CloseKey(hkey)
check RegCloseKey.call(hkey)
end
|
.CreateKey(hkey, name, opt, desired) ⇒ Object
293
294
295
296
297
298
299
|
# File 'lib/win32/registry.rb', line 293
def CreateKey(hkey, name, opt, desired)
result = packhandle(0)
disp = packdw(0)
check RegCreateKeyExW.call(hkey, make_wstr(name), 0, 0, opt, desired,
0, result, disp)
[ unpackhandle(result), unpackdw(disp) ]
end
|
.DeleteKey(hkey, name) ⇒ Object
339
340
341
|
# File 'lib/win32/registry.rb', line 339
def DeleteKey(hkey, name)
check RegDeleteKeyW.call(hkey, make_wstr(name))
end
|
.DeleteValue(hkey, name) ⇒ Object
335
336
337
|
# File 'lib/win32/registry.rb', line 335
def DeleteValue(hkey, name)
check RegDeleteValueW.call(hkey, make_wstr(name))
end
|
.EnumKey(hkey, index) ⇒ Object
308
309
310
311
312
313
314
|
# File 'lib/win32/registry.rb', line 308
def EnumKey(hkey, index)
name = WCHAR_NUL * Constants::MAX_KEY_LENGTH
size = packdw(Constants::MAX_KEY_LENGTH)
wtime = ' ' * 8
check RegEnumKeyExW.call(hkey, index, name, size, 0, 0, 0, wtime)
[ name.byteslice(0, unpackdw(size) * WCHAR_SIZE), unpackqw(wtime) ]
end
|
.EnumValue(hkey, index) ⇒ Object
301
302
303
304
305
306
|
# File 'lib/win32/registry.rb', line 301
def EnumValue(hkey, index)
name = WCHAR_NUL * Constants::MAX_KEY_LENGTH
size = packdw(Constants::MAX_KEY_LENGTH)
check RegEnumValueW.call(hkey, index, name, size, 0, 0, 0, 0)
name.byteslice(0, unpackdw(size) * WCHAR_SIZE)
end
|
.FlushKey(hkey) ⇒ Object
343
344
345
|
# File 'lib/win32/registry.rb', line 343
def FlushKey(hkey)
check RegFlushKey.call(hkey)
end
|
.make_wstr(str) ⇒ Object
283
284
285
|
# File 'lib/win32/registry.rb', line 283
def make_wstr(str)
str.encode(WCHAR)
end
|
.OpenKey(hkey, name, opt, desired) ⇒ Object
287
288
289
290
291
|
# File 'lib/win32/registry.rb', line 287
def OpenKey(hkey, name, opt, desired)
result = packhandle(0)
check RegOpenKeyExW.call(hkey, make_wstr(name), opt, desired, result)
unpackhandle(result)
end
|
.packdw(dw) ⇒ Object
265
266
267
|
# File 'lib/win32/registry.rb', line 265
def packdw(dw)
[dw].pack('V')
end
|
.packhandle(h) ⇒ Object
257
258
259
|
# File 'lib/win32/registry.rb', line 257
def packhandle(h)
win64? ? packqw(h) : packdw(h)
end
|
.packqw(qw) ⇒ Object
274
275
276
|
# File 'lib/win32/registry.rb', line 274
def packqw(qw)
[ qw & 0xFFFFFFFF, qw >> 32 ].pack('VV')
end
|
.QueryInfoKey(hkey) ⇒ Object
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
# File 'lib/win32/registry.rb', line 351
def QueryInfoKey(hkey)
subkeys = packdw(0)
maxsubkeylen = packdw(0)
values = packdw(0)
maxvaluenamelen = packdw(0)
maxvaluelen = packdw(0)
secdescs = packdw(0)
wtime = ' ' * 8
check RegQueryInfoKey.call(hkey, 0, 0, 0, subkeys, maxsubkeylen, 0,
values, maxvaluenamelen, maxvaluelen, secdescs, wtime)
[ unpackdw(subkeys), unpackdw(maxsubkeylen), unpackdw(values),
unpackdw(maxvaluenamelen), unpackdw(maxvaluelen),
unpackdw(secdescs), unpackqw(wtime) ]
end
|
.QueryValue(hkey, name) ⇒ Object
316
317
318
319
320
321
322
323
324
|
# File 'lib/win32/registry.rb', line 316
def QueryValue(hkey, name)
type = packdw(0)
size = packdw(0)
name = make_wstr(name)
check RegQueryValueExW.call(hkey, name, 0, type, 0, size)
data = "\0".force_encoding('ASCII-8BIT') * unpackdw(size)
check RegQueryValueExW.call(hkey, name, 0, type, data, size)
[ unpackdw(type), data[0, unpackdw(size)] ]
end
|
.SetValue(hkey, name, type, data, size) ⇒ Object
326
327
328
329
330
331
332
333
|
# File 'lib/win32/registry.rb', line 326
def SetValue(hkey, name, type, data, size)
case type
when REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
data = data.encode(WCHAR)
size ||= data.bytesize + WCHAR_SIZE
end
check RegSetValueExW.call(hkey, make_wstr(name), 0, type, data, size)
end
|
.unpackdw(dw) ⇒ Object
269
270
271
272
|
# File 'lib/win32/registry.rb', line 269
def unpackdw(dw)
dw += [0].pack('V')
dw.unpack('V')[0]
end
|
.unpackhandle(h) ⇒ Object
261
262
263
|
# File 'lib/win32/registry.rb', line 261
def unpackhandle(h)
win64? ? unpackqw(h) : unpackdw(h)
end
|
.unpackqw(qw) ⇒ Object
278
279
280
281
|
# File 'lib/win32/registry.rb', line 278
def unpackqw(qw)
qw = qw.unpack('VV')
(qw[1] << 32) | qw[0]
end
|
.win64? ⇒ Boolean
253
254
255
|
# File 'lib/win32/registry.rb', line 253
def win64?
/^(?:x64|x86_64)/ =~ RUBY_PLATFORM
end
|