0 out of 2 rated this helpful - Rate this topic

DeleteSetting Function

Deletes a section or key setting from an application's entry in the Windows registry.

The My feature gives you greater productivity and performance in registry operations than the DeleteSetting function. For more information, see My.Computer.Registry Object.

Public Sub DeleteSetting( _
   ByVal AppName As String, _
   Optional ByVal Section As String = Nothing, _
   Optional ByVal Key As String = Nothing _
)
AppName

Required. String expression containing the name of the application or project to which the section or key setting applies.

Section

Required. String expression containing the name of the section from which the key setting is being deleted. If only AppName and Section are provided, the specified section is deleted along with all related key settings.

Key

Optional. String expression containing the name of the key setting being deleted.

Exception type

Error number

Condition

ArgumentException

5

Section, AppName, or Key setting does not exist.

ArgumentException

5

User is not logged in.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

If all arguments are provided, the specified setting is deleted. A run-time error occurs if you attempt to use DeleteSetting on a nonexistent section or key setting.

DeleteSetting requires that a user be logged on since it operates under the HKEY_LOCAL_USER registry key, which is not active until a user logs on interactively.

Registry settings that are to be accessed from a non-interactive process (such as Mtx.exe) should be stored under either the HKEY_LOCAL_MACHINE\Software\ or the HKEY_USER\DEFAULT\Software registry keys.

The following example first uses the SaveSetting procedure to make entries in the Windows registry for the MyApp application, and then uses the DeleteSetting function to remove them. Because no Key argument is specified, the whole Startup section is deleted, including the section name and all of its keys.

' Place some settings in the registry.
SaveSetting("MyApp", "Startup", "Top", "75")
SaveSetting("MyApp","Startup", "Left", "50")
' Remove section and all its settings from registry.
DeleteSetting ("MyApp", "Startup")
' Remove MyApp from the registry.
DeleteSetting ("MyApp")


This function is not supported.

Namespace: Microsoft.VisualBasic

Module: Interaction

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Location of the setting in the registry
The setting deleted by the DeleteSetting function is a key or value under the HKCU\Software\VB and VBA Program Settings key. More specifically, it is the key named HKCU\Software\VB and VBA Program Settings\AppName or HKCU\Software\VB and VBA Program Settings\AppName\Section or the value named HKCU\Software\VB and VBA Program Settings\AppName\Section\Key, depending on how many optional parameters are set, where AppName, Section, and Key are the values of the parameters with these names specified in the call to DeleteSetting. The AppName parameter should contain the name of the applicable subkey of the HKCU\Software\VB and VBA Program Settings key, which can be anything, but is typically the name of the applicable application or project.