Information
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.

DeleteValue method of the StdRegProv class

The DeleteValue method deletes a named value in the specified subkey.

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

Syntax


uint32 DeleteValue(
  [in, optional]  uint32 hDefKey = HKEY_LOCAL_MACHINE,
  [in]            string sSubKeyName,
  [in]            string sValueName
);

Parameters

hDefKey [in, optional]

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 deleted.

sValueName [in]

The named value to be deleted from the subkey. Specify an empty string to delete the default named value. The default named value is not deleted. The value is set to the following: value not set.

Examples

The following VBScript code example shows how to use the DeleteValue method. For purposes of the example, a new key and value are created then the value is deleted.


Const HKEY_CURRENT_USER As Long = &H80000001
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
                     strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\MyKey\MySubKey"
' Create new key and value
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, strKeyPath)

If (Return = 0) And (Err.Number = 0) Then    
    Wscript.Echo "HKEY_LOCAL_MACHINE\Software\MyKey\MySubKey created"
Else
    Wscript.Echo "CreateKey failed. Error = " & Err.Number
End If
' Create new value
strValueName = "Example DWORD Value"
objReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,250
If Err = 0 Then
   objReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
   WScript.Echo "HKEY_LOCAL_MACHINE\SOFTWARE\NewKey\Example DWORD " _
                & "Value contains " & dwValue
Else 
   WScript.Echo "Error in creating key and DWORD value = " & Err.Number
' Delete new value
Return = objRegistry.DeleteValue_
    (HKEY_LOCAL_MACHINE,strKeyPath,strValueName)

If (Return = 0) And (Err.Number = 0) Then
    WScript.Echo strValueName & "Registry value HKEY_LOCAL_MACHINE," _
                 & strKeyPath & "," & strValueName & "," & dwValue & " deleted"
Else
     WScript.Echo "Registry value not deleted" & VBNewLine _
                  & "Error = " & Err.Number
End If

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Namespace

Root\default

MOF

RegEvent.mof

DLL

Stdprov.dll

See also

StdRegProv
Modifying the System Registry
WMI Tasks: Registry

 

 

Show:
© 2015 Microsoft