2 out of 5 rated this helpful - Rate this topic

SetBinaryValue method of the StdRegProv class

The SetBinaryValue method sets the data value for a named value whose data type is REG_BINARY.

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

Syntax


uint32 SetBinaryValue(
  [in]  uint32 hDefKey = HKEY_LOCAL_MACHINE,
  [in]  string sSubKeyName,
  [in]  string sValueName,
  [in]  uint8 uValue[]
);

Parameters

hDefKey [in]

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

Note that HKEY_DYN_DATA is a valid tree for computers running Windows 95 and Windows 98 only.

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))
HKEY_DYN_DATA (2147483654 (0x80000006))
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]

An array of binary data values.

Return value

In C++, the method returns a uint32 value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code that is defined in Winerror.h. In C++, use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. You can also look up return values under the WMI Error Constants.

In scripting or Visual Basic, the method returns an integer value that is 0 (zero) if successful. If the function fails, the return value is a nonzero error code that you can look up in WbemErrorEnum.

Examples

For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository. Other examples are in books and articles listed in Further Information.

For C++ code examples, see WMI C++ Application Examples.

The following VBScript code example shows how to write a new value to the REG_BINARY value that is located in HKEY_LOCAL_MACHINE\SOFTWARE\MyKey\MyBinaryNamedValue.

Const HKEY_CURRENT_USER = &H80000001
Set objRegistry = _
   GetObject("Winmgmts:root\default:StdRegProv")

strPath = "Software\MyKey"
uBinary = Array(1,2,3,4,5,6,7,8)
Return = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, _
   strPath, _
   "MyBinaryNamedValue", _
   uBinary)

If (Return = 0) And (Err.Number = 0) Then
    Wscript.Echo "Binary value added successfully"
Else
    ' An error occurred
End If

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Namespace

\root\default

MOF

Regevent.mof

DLL

Stdprov.dll

See also

StdRegProv
Modifying the System Registry
WMI Tasks: Registry

 

 

Send comments about this topic to Microsoft

Build date: 11/19/2012

Community Additions

ADD
© 2013 Microsoft. All rights reserved.