Minősítés és vélemény közlése kattintással
MSDN
MSDN Library
Web Development
Scripting
Windows Script Host
 RegWrite Method
Az összes összecsukása/Az összes kibontása Az összes összecsukása

We were unable to locate this content in hu-hu.

Here is the same content in en-us.

Ez az oldal a következőre vonatkozik:
.NET Framework 3.0

Más verziók is elérhetők a következőhöz:
Windows Script Host
RegWrite Method

Creates a new key, adds another value-name to an existing key (and assigns it a value), or changes the value of an existing value-name.

object.RegWrite(strName, anyValue [,strType])
object

WshShell object.

strName

String value indicating the key-name, value-name, or value you want to create, add, or change.

anyValue

The name of the new key you want to create, the name of the value you want to add to an existing key, or the new value you want to assign to an existing value-name.

strType

Optional. String value indicating the value's data type.

Specify a key-name by ending strName with a final backslash. Do not include a final backslash to specify a value name. The RegWrite method automatically converts the parameter anyValue to either a string or an integer. The value of strType determines its data type (either a string or an integer). The options for strType are listed in the following table.

Converted to

strType

String

REG_SZ

String

REG_EXPAND_SZ

Integer

REG_DWORD

Integer

REG_BINARY

NoteNote:

The REG_MULTI_SZ type is not supported for the RegWrite method.

TipTip:

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. The five 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

The four possible data types you can specify with strType are listed in the following table.

Type

Description

In the Form of

REG_SZ

A string

A string

REG_DWORD

A number

An integer

REG_BINARY

A binary value

An integer

REG_EXPAND_SZ

An expandable string (e.g., "%windir%\\calc.exe")

A string

The following code creates a key and two values, reads them, and deletes them.

VBScript
Dim WshShell, bKey
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell. RegWrite"HKCU\Software\ACME\FortuneTeller\", 1, "REG_BINARY"
WshShell. RegWrite"HKCU\Software\ACME\FortuneTeller\MindReader", "Goocher!", "REG_SZ"

bKey = WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\")
WScript.Echo WshShell.RegRead("HKCU\Software\ACME\FortuneTeller\MindReader")

WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\MindReader"
WshShell.RegDelete "HKCU\Software\ACME\FortuneTeller\"
WshShell.RegDelete "HKCU\Software\ACME\"
JScript
var WshShell = WScript.CreateObject("WScript.Shell");

WshShell.RegWrite ("HKCU\\Software\\ACME\\FortuneTeller\\", 1, "REG_BINARY");
WshShell.RegWrite ("HKCU\\Software\\ACME\\FortuneTeller\\MindReader", "Goocher!", "REG_SZ");

var bKey =    WshShell.RegRead ("HKCU\\Software\\ACME\\FortuneTeller\\");
WScript.Echo (WshShell.RegRead ("HKCU\\Software\\ACME\\FortuneTeller\\MindReader"));

WshShell.RegDelete ("HKCU\\Software\\ACME\\FortuneTeller\\MindReader");
WshShell.RegDelete ("HKCU\\Software\\ACME\\FortuneTeller\\");
WshShell.RegDelete ("HKCU\\Software\\ACME\\");

Applies To:

Közösségi tartalom   Mi a közösségi tartalom?
Új tartalom hozzáadása RSS  Jegyzetek
Unable to Use a "\" in the Key Name with the RegWrite Method of Windows Script Host      Jezza080808   |   Szerkesztés   |   Előzmények megjelenítése
I was trying to update the registry with a key name that had a \ in it. I spent some time tring to track down a solution to this issue. See kb281309 for details and alternate solutions.
Megjelölés mint ContentBug
Using a backslash in registry key...      ericm301 ... Thomas Lee   |   Szerkesztés   |   Előzmények megjelenítése
The backslash in a JavaScript string is a special charater indicating that the next character (or group) is a special character.
For example, in a webpage script:

window.alert( "Gimme a newline!\nThere you go!" );
Will output a message box with two lines, because the '\n' sequence starts a new line, specifically sending the CR+LF combo in Windows.

Another example, for WScript:
WScript.Echo( "Tabs\tare\tus." );
will output an echobox (or console output) the three words with tabs between.

The way to include a backslash is to put two of them in the character string:
// from an hta script...
var wsShell = ActiveXObject("WScript.Shell"); // yes, you can access the shell from an hta, but be careful!
var str = "HKCU\Software\Microsoft\Internet Explorer\PageSetup\margin_top";
var str2 = "HKCU\\Software\\Microsoft\\Internet Explorer\\PageSetup\\margin_top";
alert( wsShell.RegRead( str ) ); // This won't work
alert( wsShell.RegRead( str2 ) );
// and just for fun...
alert( str + "\n" + str2 );
Megjelölés mint ContentBug
Processing
© 2009 Microsoft Corporation. Minden jog fenntartva. Felhasználási feltételek | Védjegyek | Adatvédelmi nyilatkozat
Page view tracker