mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
Add winreg typings.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/// <reference path="winreg.d.ts" />
|
||||
|
||||
var regKey = new Winreg({
|
||||
hive: Winreg.HKCU,
|
||||
key: "\\Foo\\Bar",
|
||||
host: "\\FooBar"
|
||||
})
|
||||
|
||||
var regKey2 = new Winreg({
|
||||
hive: Winreg.HKCU,
|
||||
key: "\\Foo\\Bar"
|
||||
})
|
||||
|
||||
var regKey3 = new Winreg({
|
||||
key: "\\Foo\\Bar"
|
||||
})
|
||||
|
||||
var str: string = regKey.parent.key
|
||||
var par: Winreg = regKey.parent
|
||||
|
||||
regKey.values((err, items) => {
|
||||
var itemsC: Array<Winreg.RegistryItem> = items;
|
||||
var errorC: Error = err;
|
||||
|
||||
items.forEach((item) => {
|
||||
var str: string = item.host;
|
||||
});
|
||||
});
|
||||
|
||||
regKey.keys((err, items) => {
|
||||
var itemsC: Array<Winreg> = items;
|
||||
var errorC: Error = err;
|
||||
|
||||
items.forEach((item) => {
|
||||
var regKey4: Winreg = item;
|
||||
});
|
||||
});
|
||||
|
||||
//--- TEST CASE ---
|
||||
|
||||
// create a registry client
|
||||
var r1 = new Winreg({
|
||||
hive: Winreg.HKCU,
|
||||
key: '\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'
|
||||
})
|
||||
var r2 = new Winreg({
|
||||
hive: Winreg.HKCU,
|
||||
key: '\\Control Panel\\Desktop'
|
||||
})
|
||||
|
||||
// get parent key
|
||||
console.log('parent of "'+r2.path+'" -> "'+r2.parent.path+'"');
|
||||
|
||||
// list subkeys
|
||||
r2.keys(function (err, items) {
|
||||
|
||||
if (!err) {
|
||||
for (var i = 0, l = items.length; i < l; i++) {
|
||||
console.log('subkey of "'+r2.path+'": '+items[i].path);
|
||||
}
|
||||
}
|
||||
|
||||
// list values
|
||||
r1.values(function (err, items) {
|
||||
|
||||
if (!err) {
|
||||
console.log(JSON.stringify(items, null, '\t'));
|
||||
}
|
||||
|
||||
// query named value
|
||||
r1.get(items[0].name, function (err, item) {
|
||||
|
||||
if (!err) {
|
||||
console.log(JSON.stringify(item, null, '\t'));
|
||||
}
|
||||
|
||||
// add value
|
||||
r1.set('bla', Winreg.REG_SZ, 'hello world!', function (err) {
|
||||
|
||||
if (!err) {
|
||||
console.log('value written');
|
||||
}
|
||||
|
||||
// delete value
|
||||
r1.remove('bla', function (err) {
|
||||
|
||||
if (!err) {
|
||||
console.log('value deleted');
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Vendored
+248
@@ -0,0 +1,248 @@
|
||||
// Type definitions for Winreg v0.0.15
|
||||
// Project: https://github.com/fresc81/node-winreg/
|
||||
// Definitions by: RX14 <https://github.com/RX14>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare var Winreg: WinregStatic;
|
||||
|
||||
interface WinregStatic {
|
||||
/**
|
||||
* Create a new Winreg instance with the given options.
|
||||
* @param options options object
|
||||
*/
|
||||
new (options: Winreg.Options): Winreg;
|
||||
|
||||
/**
|
||||
* HKEY_LOCAL_MACHINE registry hive.
|
||||
*/
|
||||
HKLM: string;
|
||||
|
||||
/**
|
||||
* HKEY_CURRENT_USER registry hive.
|
||||
*/
|
||||
HKCU: string;
|
||||
|
||||
/**
|
||||
* HKEY_CLASSES_ROOT registry hive.
|
||||
*/
|
||||
HKCR: string;
|
||||
|
||||
/**
|
||||
* HKEY_USERS registry hive.
|
||||
*/
|
||||
HKU: string;
|
||||
|
||||
/**
|
||||
* HKEY_CURRENT_CONFIG registry hive.
|
||||
*/
|
||||
HKCC: string;
|
||||
|
||||
/**
|
||||
* Array of available registry hives.
|
||||
*/
|
||||
HIVES: Array<string>;
|
||||
|
||||
/**
|
||||
* Registry value type STRING.
|
||||
*
|
||||
* Values of this type contain a string.
|
||||
*/
|
||||
REG_SZ: string;
|
||||
|
||||
/**
|
||||
* Registry value type MULTILINE_STRING.
|
||||
*
|
||||
* Values of this type contain a multiline string.
|
||||
*/
|
||||
REG_MULTI_SZ: string;
|
||||
|
||||
/**
|
||||
* Registry value type EXPANDABLE_STRING.
|
||||
*
|
||||
* Values of this type contain an expandable string.
|
||||
*/
|
||||
REG_EXPAND_SZ: string;
|
||||
|
||||
/**
|
||||
* Registry value type DOUBLE_WORD.
|
||||
*
|
||||
* Values of this type contain a double word (32 bit integer).
|
||||
*/
|
||||
REG_DWORD: string;
|
||||
|
||||
/**
|
||||
* Registry value type QUAD_WORD.
|
||||
*
|
||||
* Values of this type contain a quad word (64 bit integer).
|
||||
*/
|
||||
REG_QWORD: string;
|
||||
|
||||
/**
|
||||
* Registry value type BINARY.
|
||||
*
|
||||
* Values of this type contain a binary value.
|
||||
*/
|
||||
REG_BINARY: string;
|
||||
|
||||
/**
|
||||
* Registry value type UNKNOWN.
|
||||
*
|
||||
* Values of this type contain a value of an unknown type.
|
||||
*/
|
||||
REG_NONE: string;
|
||||
|
||||
/**
|
||||
* Array of available registry value types.
|
||||
*/
|
||||
REG_TYPES: Array<string>;
|
||||
}
|
||||
|
||||
interface Winreg {
|
||||
/**
|
||||
* Hostname, if set in options.
|
||||
* @readonly
|
||||
*/
|
||||
host: string;
|
||||
|
||||
/**
|
||||
* Hive ID.
|
||||
* @readonly
|
||||
*/
|
||||
hive: string;
|
||||
|
||||
/**
|
||||
* The registry key.
|
||||
* @readonly
|
||||
*/
|
||||
key: string;
|
||||
|
||||
/**
|
||||
* The path of the registry key, including hostname (if set) and hive.
|
||||
* @readonly
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* A new Winreg instance of the parent key.
|
||||
* @readonly
|
||||
*/
|
||||
parent: Winreg;
|
||||
|
||||
/**
|
||||
* Retrieves all values from this registry key.
|
||||
*
|
||||
* @param cb Callback with an array of RegistryItem objects, one for each value.
|
||||
*/
|
||||
values(cb: (err: Error, result: Array<Winreg.RegistryItem>) => void): void;
|
||||
|
||||
/**
|
||||
* Retrieves all subkeys of this registry key.
|
||||
*
|
||||
* @param cb Callback with an array of Winreg objects, one for each subkey.
|
||||
*/
|
||||
keys(cb: (err: Error, result: Array<Winreg>) => void): void;
|
||||
|
||||
/**
|
||||
* Retrieves a named value from this registry key.
|
||||
*
|
||||
* @param name Name of the value to retrieve.
|
||||
* @param cb Callback with a RegistryItem object for the value.
|
||||
*/
|
||||
get(name: string, cb: (err: Error, result: Winreg.RegistryItem) => void): void;
|
||||
|
||||
/**
|
||||
* Sets a named value in this registry key. Overwrites existing value.
|
||||
*
|
||||
* @param name Name of the value to set.
|
||||
* @param type Type of the value to set.
|
||||
* @param value Value of value to set.
|
||||
* @param cb Callback with any errors.
|
||||
*/
|
||||
set(name: string, type: string, value: string, cb: (err: Error) => void): void;
|
||||
|
||||
/**
|
||||
* Remove a named value from this registry key.
|
||||
*
|
||||
* @param name Name of the value to remove.
|
||||
* @param cb Callback with any errors.
|
||||
*/
|
||||
remove(name: string, cb: (err: Error) => void): void;
|
||||
|
||||
/**
|
||||
* Create this registry key.
|
||||
*
|
||||
* @param cb Callback with any errors.
|
||||
*/
|
||||
create(cb: (err: Error) => void): void;
|
||||
|
||||
/**
|
||||
* Erase this registry key and its contents.
|
||||
*
|
||||
* @param cb Callback with any errors.
|
||||
*/
|
||||
erase(cb: (err: Error) => void): void;
|
||||
}
|
||||
|
||||
declare namespace Winreg {
|
||||
export interface Options {
|
||||
/**
|
||||
* Optional hostname, must start with '\\' sequence.
|
||||
*/
|
||||
host?: string;
|
||||
|
||||
/**
|
||||
* Optional hive ID, default is HKLM.
|
||||
*/
|
||||
hive?: string;
|
||||
|
||||
/**
|
||||
* Optional key, default is the root key.
|
||||
*/
|
||||
key?: String;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single registry value record
|
||||
*/
|
||||
interface RegistryItem {
|
||||
/**
|
||||
* Hostname, if set in options.
|
||||
* @readonly
|
||||
*/
|
||||
host: string;
|
||||
|
||||
/**
|
||||
* Hive ID.
|
||||
* @readonly
|
||||
*/
|
||||
hive: string;
|
||||
|
||||
/**
|
||||
* Key that the registry value belongs to.
|
||||
* @readonly
|
||||
*/
|
||||
key: string;
|
||||
|
||||
/**
|
||||
* Name of the registry value.
|
||||
* @readonly
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Type of the registry value.
|
||||
* @readonly
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* Value of the registry value, as a string.
|
||||
* @readonly
|
||||
*/
|
||||
value: string;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "winreg" {
|
||||
export = Winreg;
|
||||
}
|
||||
Reference in New Issue
Block a user