The Windows registry consists of 5 sections. These sections, their short descriptions, and some aliases are summarized in the table below.
| Short name | Full name | Description |
|---|---|---|
| HKCU | HKEY_CURRENT_USER | Controls configuration settings for the current user. |
| HKLM | HKEY_LOCAL_MACHINE | Controls system-level configuration settings. |
| HKCR | HKEY_CLASSES_ROOT | Configuration settings for applications and files. Ensures the correct application is opened when a file is started through WIndows Explorer or OLE. |
| HKEY_USERS | Stores default-user and other-user settings by profile. | |
| HKEY_CURRENT_CONFIG | Contains information about the hardware profile being used. |
The values of registry keys can have one of the following types:
RegRead(keyName)where keyName is a 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 |
RegWrite(keyName, anyValue [,type])where
Note The REG_MULTI_SZ type is not supported for the RegWrite method.
Note RegWrite will write at most one DWORD to a REG_BINARY value. Larger values are not supported with
this method. Fully qualified key-names and value-names are prefixed with a root key. You may use abbreviated versions of
root key names with the RegWrite method.
RegDelete(keyName)where keyName is a string value indicating the name of the registry key or key value you want to delete.
Specify a key-name by ending keyName with a final backslash; leave it off to specify a value-name. Fully qualified key-names and value-names are prefixed with a root key. You may use abbreviated versions of root key names with the RegDelete method.
The following example shows how to check if your IE browser has your favorite page set as a start page and sets it if it's not.
var page = "http://www.google.com";
var msg1 = "You start up page is '";
var msg2 = "'. Do you want to reset your favorite page?";
var title = "Start page has been changed";
var path = "HKCU\\Software\\Microsoft\\Internet Explorer\\Main\\";
var key = "Start Page";
var shell = WScript.CreateObject("WScript.Shell");
try{
var spage = shell.RegRead(path+key);
if( spage != page )
if( shell.Popup(msg1+spage+msg2, 0, title, 4+32) == 6 ){
shell.RegWrite(path+key, page);
WScript.Echo("Your start page is reset to '"+page+"'");
}
}
catch( e ){
var code = e.number & 0xFFFF;
var msg = "Error " + code + ": " + e.description;
shell.Popup(msg, 0, "Run-time error in the script "+WScript.ScriptName, 16);
}
The following script sets the auto-logon option to ON.
var AutoAdminLogon, DefaultUserName, DefaultPassword, DontDisplayLastUserName;
var logon = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\";
// read the current values
try{ AutoAdminLogon = shell.RegRead(logon+"AutoAdminLogon"); }
catch(e){ AutoAdminLogon = "--no value--"; }
try{ DefaultUserName = shell.RegRead(logon+"DefaultUserName"); }
catch(e){ DefaultUserName = "--no value--"; }
try{ DefaultPassword = shell.RegRead(logon+"DefaultPassword"); }
catch(e){ DefaultPassword = "--no value--"; }
try{ DontDisplayLastUserName = shell.RegRead(logon+"DontDisplayLastUserName"); }
catch(e){ DontDisplayLastUserName = "--no value--"; }
str = "AutoAdminLogon: "+AutoAdminLogon+"\n"+
"DefaultUserName: "+DefaultUserName+"\n"+
"DefaultPassword: "+DefaultPassword+"\n"+
"DontDisplayLastUserName: "+DontDisplayLastUserName+"\n";
WScript.Echo(str);
try{
// set autologon
shell.RegWrite(logon+"AutoAdminLogon", "1", "REG_SZ");
shell.RegWrite(logon+"DefaultUserName", "administrator", "REG_SZ");
shell.RegWrite(logon+"DefaultPassword", "test", "REG_SZ");
shell.RegWrite(logon+"DontDisplayLastUserName", "0", "REG_SZ");
}
catch( e ){
var code = e.number & 0xFFFF;
var msg = "Error " + code + ": " + e.description;
shell.Popup(msg, 0, "Run-time error in the script "+WScript.ScriptName, 16);
}