Delete Setting Statement Named Arguments

PC Repair Tools

Advanced Registry Cleaner PC Diagnosis and Repair

Get Instant Access


DeleteSetting appname[, section[, key]] appname

Use: Required

Data Type: String

The name of the application. This must be a subkey of the HKEY_ CURRENT_USER\Software\VB and VBA Program Settings registry key.


Use: Optional

Data Type: String

The name of the application key's subkey that is to be deleted. section can be a single key or a registry path separated with backslashes.

Use: Optional Data Type: String

The name of the value entry to delete. Description

Deletes a complete application key, one of its subkeys, or a single value entry from the Windows registry.

Rules at a Glance

• section can contain a relative path (similar to that used to describe the folders on a hard drive) to navigate from the application key to the subkey to be deleted. For example, to delete the value entry named TestKey in the registry key HKEY_CURRENT_USER\Software\VB and VBA Program Settings\ RegTester\BranchOne\BranchTwo, you'd use:

DeleteSetting "RegTester", "BranchOne\BranchTwo", _ "TestKey"

• You can't use DeleteSetting to delete entries from registry keys that aren't subkeys of HKEY_CURRENT_USER\Software\VB and VBA Program Settings.

220 Chapter 7- The Language Reference

• If key is supplied, only the value entry named key and its associated value are deleted.

• If key is omitted, the subkey named section is deleted.

• If section is omitted, the entire application key named appname is deleted.


Sub TestTheReg()

SaveSetting "MyRealGoodApp", _

"TestBranch\SomeSection\AnotherSection", _ " Testkey ", "10" MsgBox "Now look in RegEdit" End Sub

Sub TestDelete()

If GetSetting("MyRealGoodApp", _

"TestBranch\SomeSection\AnotherSection", _ "") = "" Then

DeleteSetting "MyRealGoodApp", _ "TestBranch\SomeSection\AnotherSection", _ "TestKey"

MsgBox "Look again!"

End If End Sub

Programming Tips & Gotchas

• DeleteSetting was designed to operate on initialization files on 16-bit platforms and on the registry on 32-bit platforms. But the terminology that describes the statement in the official documentation is based on initialization files, rather than on the registry. In particular, what is described as a key is a named key in an initialization file and a value entry in the registry.

• The behavior of the DeleteSetting statement differs under Windows 95 and Windows NT when it's used to remove a key from the registry. Under Windows 95, if the statement deletes either appname or section, all subkeys belonging to the key to be deleted are also deleted. Under Windows NT, on the other hand, the keys appname and section are deleted only if they contain no subkeys.

• DeleteSetting can't delete the default value (that is, the unnamed value entry) belonging to any key. If you're using only the VB registry functions, though, this isn't a serious limitation, since SaveSetting doesn't allow you to create a default value.

• Unless you are quite sure what you're doing, you should delete only registry settings that have been placed in the registry by your own code. Inadvertently deleting the wrong entries can have disastrous consequences. However, because this statement gives you access only to the subkeys of HKEY_ CURRENT_USER\Software\VB and VBA Program Settings, the potential damage is minimized.

DeleteSetting Statement 221

• Never assume that the key you want to delete is necessarily present in the registry. DeleteSetting deletes a user key (that is, a subkey of HKEY_ CURRENT_USER); except on Win95 systems that aren't configured to support multiple users, the user key is formed from a file that reflects only the present user's settings. This means that when one user runs an application, user settings are stored in his or her registry key. But when a second user runs the application for the first time, settings for that user aren't likely to be there. Attempting to delete a nonexistent key produces runtime error 5, "Invalid procedure call or argument." To prevent the error, you should first test for the presence of the registry key, as shown in the previous example.

• For full details of how to work properly with the registry, see Inside the Windows 95 Registry, written by Ron Petrusha, published by O'Reilly & Associates.

See Also

GetAllSettings Function, GetSetting Function, SaveSetting Statement

Was this article helpful?

0 0


  • billy
    What is vb and vba program settings?
    8 years ago

Post a comment