Returns a key setting value from an application's entry in the Windows registry.
Public Function GetSetting( _ ByVal AppName As String, _ ByVal Section As String, _ ByVal Key As String, _ Optional ByVal Default As String = "" _ ) As String
Exception type | Error number | Condition |
---|---|---|
5 | One or more arguments are not String expressions, or user is not logged in. |
If any of the items named in the GetSetting arguments do not exist, GetSetting returns a value of Default.
GetSetting 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.
This example first uses the SaveSetting statement to make entries in the Windows registry for the application specified as AppName, and then uses the GetSetting function to display one of the settings. Because the Default argument is specified, some value is guaranteed to be returned. Note that Section names can't be retrieved with GetSetting. Finally, the DeleteSetting statement removes all the application's entries.
' Place some settings in the registry. SaveSetting("MyApp", "Startup", "Top", "75") SaveSetting("MyApp", "Startup", "Left", "50") Console.WriteLine(GetSetting("MyApp", "Startup", "Left", "25")) DeleteSetting("MyApp")
DeleteSetting Function | GetAllSettings Function | SaveSetting Function |