DeleteKey method of the StdRegProv Class
Applies to: desktop apps only
The DeleteKey method deletes a subkey in the specified tree.
This topic uses Managed Object Format (MOF) syntax. For more information about using this method, see Calling a Method.
Syntax
uint32 DeleteKey( [in, optional] uint32 hDefKey = HKEY_LOCAL_MACHINE, [in] string sSubKeyName );
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]
-
The key to be deleted.
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 DeleteKey method to delete the MySubKey subkey created in the CreateKey example.
const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objReg=GetObject("winmgmts:"_ & "{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") KeyPath = "Software\MyKey\MySubKey" ' Create new key 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 'Delete new key Return = objReg.DeleteKey(HKEY_LOCAL_MACHINE, KeyPath) If (Return = 0) And (Err.Number = 0) Then Wscript.Echo _ "HKEY_LOCAL_MACHINE\Software\MyKey\MySubKey" & _ " successfully deleted" Else Wscript.Echo "DeleteKey failed. Error = " & Err.Number End If
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Namespace |
\root\default |
|
MOF |
|
|
DLL |
|
See also
Send comments about this topic to Microsoft
Build date: 3/9/2012