The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SetDWORDValue method of the StdRegProv class

The SetDWORDValue method sets the data value for a named value whose data type is REG_DWORD.

This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.


uint32 SetDWORDValue(
  [in]  uint32 hDefKey = HKEY_LOCAL_MACHINE,
  [in]  string sSubKeyName,
  [in]  string sValueName,
  [in]  uint32 uValue


hDefKey [in]

A registry tree, also known as a hive, that contains the sSubKeyName path. The default value is HKEY_LOCAL_MACHINE.

The following trees are defined in WinReg.h.

HKEY_CLASSES_ROOT (2147483648 (0x80000000))
HKEY_CURRENT_USER (2147483649 (0x80000001))
HKEY_LOCAL_MACHINE (2147483650 (0x80000002))
HKEY_USERS (2147483651 (0x80000003))
HKEY_CURRENT_CONFIG (2147483653 (0x80000005))
sSubKeyName [in]

A key that contains the named value to be set.

sValueName [in]

A named value whose data value you are setting. You can specify an existing named value (update) or a new named value (create). Specify an empty string to set the data value for the default named value.

uValue [in]

A DWORD data value.


Changing the values of registry entries is a common registry management task. The most challenging aspect of that task is determining which entries you need to change, and to which values they must be changed. After you have this information, you must choose the appropriate Registry Provider methods for making the change.

To change a string value (REG_SZ), you use the SetStringValue method; to change a numeric value (DWORD), you use the SetDWORDValue method. Each of these methods takes four parameters:

  • A constant that specifies the subtree in which the value being changed is located.
  • The path to the subkey in which the value is located.
  • The name of the entry with the value to be changed.
  • The new value.

These parameters are similar to the parameters used to read registry entries. The only difference is that when registry entries are read, the fourth parameter represents the value read from the registry; when registry entries are configured, the fourth parameter represents the new value being written to the registry.

Be certain to investigate whether other methods of configuration are available before deciding to script direct changes to the registry.

Caution  Regardless of where you obtain your information, always back up the registry before modifying it in any way.


The following VBScript code example shows how to create HKEY_LOCAL_MACHINE\SOFTWARE\NewKey\Example DWORD Value and write a value of type REG_DWORD to it. If NewKey already exists then the value is added to it. You can use a registry editor such as regedt32 to view the results of the script.

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject( _
    "winmgmts:{impersonationLevel=impersonate}!\\" &_ 
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\NewKey"
strValueName = "Example DWORD Value"
oReg.SetDWORDValue _ 
If Err = 0 Then
   oReg.GetDWORDValue _
   WScript.Echo _
       "HKEY_LOCAL_MACHINE\SOFTWARE\NewKey\Example DWORD Value " _
      & "contains " & dwValue
   WScript.Echo "Error in creating key" & _
       " and DWORD value = " & Err.Number
End If


Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003







See also

Modifying the System Registry
WMI Tasks: Registry



© 2015 Microsoft