JScript中的注册表操作
JScript中WScipt.Shell对象有三个关于注册表操作的函数,即RegRead,RegWrite和RegDelete.(以下内容摘自MSDN,另外我加上了一些示例和注释)
1,RegRead
Returns the value of a key or value-name from the registry.
object.RegRead(strName)
- object
WshShell object.
- strName
String value indicating the key or value-name whose value you want.
The RegRead method returns values of the following five types.
Type | Description | In the Form of |
---|---|---|
REG_SZ | A string | A string |
REG_DWORD | A number | An integer |
REG_BINARY | A binary value | A VBArray of integers |
REG_EXPAND_SZ | An expandable string (e.g., "%windir%\\calc.exe") | A string |
REG_MULTI_SZ | An array of strings | A VBArray of strings |
You can specify a key-name by ending strName with a final backslash. Do not include a final backslash to specify a value-name. A value entry has three parts: its name, its data type, and its value. When you specify a key-name (as opposed to a value-name), RegRead returns the default value. To read a key's default value, specify the name of the key itself. Fully qualified key-names and value-names begin with a root key. You may use abbreviated versions of root key names with the RegRead method. The five possible root keys are listed in the following table.
Root key Name | Abbreviation |
---|---|
HKEY_CURRENT_USER | HKCU |
HKEY_LOCAL_MACHINE | HKLM |
HKEY_CLASSES_ROOT | HKCR |
HKEY_USERS | HKEY_USERS |
HKEY_CURRENT_CONFIG | HKEY_CURRENT_CONFIG |
示例:
var shell = new ActiveXObject("WScript.Shell");
//If the value name or key name does not exist,then an exception will throwed!
var key1 = shell.RegRead("HKEY_CURRENT_USER\\Liang\\bvalue");//suppose bvalue is of type REG_BINARY
var array1=new VBArray(key1);
var array=array1.toArray();
var msg="";
for(var i=0;i<array.length;i++)
msg += array[i].toString(16)+" ";
WScript.Echo(msg);