Interaction.SaveSetting(String, String, String, String) 方法
定义
public:
static void SaveSetting(System::String ^ AppName, System::String ^ Section, System::String ^ Key, System::String ^ Setting);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static void SaveSetting (string AppName, string Section, string Key, string Setting);
public static void SaveSetting (string AppName, string Section, string Key, string Setting);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member SaveSetting : string * string * string * string -> unit
static member SaveSetting : string * string * string * string -> unit
Public Sub SaveSetting (AppName As String, Section As String, Key As String, Setting As String)
参数
- AppName
- String
必需。Required. String 表达式,包含应用该设置的应用程序或项目的名称。String expression containing the name of the application or project to which the setting applies.
- Section
- String
必需。Required. String 表达式,包含在其中保存项设置的节的名称。String expression containing the name of the section in which the key setting is being saved.
- Key
- String
必需。Required. String 表达式,包含将保存的项设置的名称。String expression containing the name of the key setting being saved.
- Setting
- String
必需。Required. 包含值的表达式,Key 将被设置为该值。Expression containing the value to which Key is being set.
- 属性
例外
未能创建注册表项,或用户没有登录。Key registry could not be created, or user is not logged in.
示例
下面的示例首先使用 SaveSetting 函数为应用程序的 Windows 注册表中的条目 MyApp ,然后使用 DeleteSetting 函数将其删除。The following example first uses the SaveSetting function to make entries in the Windows registry for the MyApp application, and then uses the DeleteSetting function to remove them.
' Place some settings in the registry.
SaveSetting("MyApp", "Startup", "Top", "75")
SaveSetting("MyApp", "Startup", "Left", "50")
' Remove Startup section and all its settings from registry.
DeleteSetting("MyApp", "Startup")
' Remove MyApp from the registry.
DeleteSetting("MyApp")
注解
SaveSetting函数将项添加到 HKEY_CURRENT_USER\Software\VB and VBA Program Settings 中。The SaveSetting function adds the key to HKEY_CURRENT_USER\Software\VB and VBA Program Settings.
如果由于任何原因而无法保存密钥设置,则会发生错误。If the key setting cannot be saved for any reason, an error occurs.
SaveSetting 要求用户登录,因为它在 HKEY_LOCAL_USER 用户以交互方式登录之前处于不活动状态的注册表项下运行。SaveSetting 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.
要从非交互式进程访问的注册表设置 (例如 Mtx.exe) 应存储在 HKEY_LOCAL_MACHINE\Software\ 或 HKEY_USER\DEFAULT\Software 注册表项下。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.
SaveSetting需要 Write 和 Create RegistryPermission 。SaveSetting requires Write and CreateRegistryPermission .