DeleteSetting Procedure

   
DeleteSetting Procedure

Class

Microsoft.VisualBasic.Interaction

Syntax

 DeleteSetting(   appname   [,   section   [,   key   ]]) 
appname (required; String)

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

section (optional; 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.

key (optional; 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 would use:

     DeleteSetting "RegTester", "BranchOne\BranchTwo", _               "TestKey" 
  • You cannot use DeleteSetting to delete entries from registry keys that are not subkeys of HKEY_CURRENT_USER\Software\VB and VBA Program Settings .

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

Example

 Sub TestTheReg(  )     SaveSetting("MyRealGoodApp", _          "TestBranch\SomeSection\AnotherSection", _          "Testkey", "10")     MsgBox("Now look in RegEdit") End Sub Sub TestDelete(  )         If GetSetting("MyRealGoodApp", _                  "TestBranch\SomeSection\AnotherSection", _                  "TestKey") <> "" Then       DeleteSetting("MyRealGoodApp", _       "TestBranch\SomeSection\AnotherSection", _       "TestKey")       MsgBox("Look again!")    End If End Sub 

Programming Tips and Gotchas

  • DeleteSetting was designed to operate on initialization files in 16-bit platforms and on the registry in 32-bit platforms. But the terminology used to describe 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 is used to remove a key from the registry. Under Windows 95, if the statement is used to delete either appname or section , all subkeys belonging to the key to be deleted will also be deleted. Under Windows NT, on the other hand, the keys appname and section are only deleted if they don't contain subkeys.

  • DeleteSetting cannot be used to delete the default value (i.e., 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 does not allow you to create a default value.

  • Unless you are quite sure about what you're doing, you should only delete 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 only gives you access to the subkeys of HKEY_CURRENT_USER\Software\VB and VBA Program Settings , the potential damage is minimized.

  • 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 Windows 95 systems that are not 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 registry key. But when a second user runs the application for the first time, settings for that user are not likely to be present. 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 earlier example.

  • Rather than rely on the relatively underpowered registry-access functionality available in Visual Basic, we highly recommend that you instead use the Registry and RegistryKey classes available in the BCL's Microsoft.Win32 namespace.

See Also

GetAllSettings Function, GetSetting Function, SaveSetting Procedure

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net