mirror of
https://github.com/Septh/libwin32
synced 2026-08-09 12:19:58 +00:00
feat(demos): update demos
This commit is contained in:
+21
-17
@@ -5,7 +5,9 @@
|
||||
*/
|
||||
import {
|
||||
RegOpenKeyEx, RegQueryInfoKey, RegEnumKeyEx, RegEnumValue, RegCloseKey,
|
||||
type HKEY
|
||||
isHandle,
|
||||
type HKEY,
|
||||
isErrorStatus,
|
||||
} from 'libwin32'
|
||||
import { HKEY_, KEY_ } from 'libwin32/consts'
|
||||
|
||||
@@ -13,30 +15,32 @@ function QueryKey(hKey: HKEY) {
|
||||
|
||||
// Get the class name and the value count.
|
||||
const info = RegQueryInfoKey(hKey)
|
||||
if (typeof info === 'object') {
|
||||
if (isErrorStatus(info))
|
||||
return
|
||||
|
||||
// Enumerate the subkeys, until RegEnumKeyEx fails.
|
||||
console.log('Number of subkeys: %d', info.subKeys)
|
||||
for (let i = 0; i < info.subKeys; i++) {
|
||||
const key = RegEnumKeyEx(hKey, i)
|
||||
if (typeof key === 'object') {
|
||||
console.log('(%d) %s', i + 1, key.name)
|
||||
}
|
||||
// Enumerate the subkeys, until RegEnumKeyEx fails.
|
||||
console.log('Number of subkeys: %d', info.subKeys)
|
||||
for (let i = 0; i < info.subKeys; i++) {
|
||||
const key = RegEnumKeyEx(hKey, i)
|
||||
if (typeof key === 'object') {
|
||||
console.log('(%d) %s', i + 1, key.name)
|
||||
}
|
||||
}
|
||||
|
||||
// Enumerate the key values.
|
||||
console.log('Number of values: %d', info.values)
|
||||
for (let i = 0; i < info.values; i++) {
|
||||
const value = RegEnumValue(hKey, i)
|
||||
if (typeof value === 'object') {
|
||||
console.log('(%d) %s', i + 1, value.name)
|
||||
}
|
||||
// Enumerate the key values.
|
||||
console.log('Number of values: %d', info.values)
|
||||
for (let i = 0; i < info.values; i++) {
|
||||
const value = RegEnumValue(hKey, i)
|
||||
if (isErrorStatus(value)) {
|
||||
}
|
||||
else {
|
||||
console.log('(%d) %s', i + 1, value.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const hTestKey = RegOpenKeyEx(HKEY_.CURRENT_USER, "SOFTWARE\\Microsoft", 0, KEY_.READ)
|
||||
if (typeof hTestKey === 'object') {
|
||||
if (isHandle<HKEY>(hTestKey)) {
|
||||
QueryKey(hTestKey)
|
||||
RegCloseKey(hTestKey)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user