Export (0) Print
Expand All

Interaction.GetSetting Method

Returns a key setting value from an application's entry in the Windows registry. The My feature gives you greater productivity and performance in registry operations than GetAllSettings. For more information, see Registry.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static string GetSetting(
	string AppName,
	string Section,
	string Key,
	string Default
)

Parameters

AppName
Type: System.String
Required. String expression containing the name of the application or project whose key setting is requested.
Section
Type: System.String
Required. String expression containing the name of the section in which the key setting is found.
Key
Type: System.String
Required. String expression containing the name of the key setting to return.
Default
Type: System.String
Optional. Expression containing the value to return if no value is set in the Key setting. If omitted, Default is assumed to be a zero-length string ("").

Return Value

Type: System.String
Returns a key setting value from an application's entry in the Windows registry.
The My feature gives you greater productivity and performance in registry operations than GetAllSettings.

ExceptionCondition
ArgumentException

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.

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

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.

GetSetting requires Read RegistryPermission .

This example first uses the SaveSetting function 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. Notice that Section names cannot be retrieved with GetSetting. Finally, the DeleteSetting function 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")


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft