1 out of 2 rated this helpful - Rate this topic

DeleteValue method of the StdRegProv Class

Applies to: desktop apps only

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.

Note that HKEY_DYN_DATA is a valid tree for Windows 95 and Windows 98 computers 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 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

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 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")
KeyPath = "Software\MyKey\MySubKey"
' Create new key and value
Return = objReg.CreateKey(HKEY_LOCAL_MACHINE, KeyPath)

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 2000 Professional

Minimum supported server

Windows 2000 Server

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: 3/9/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ