Interaction.GetSetting(String, String, String, String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會從應用程式在 Windows 登錄檔的項目中回傳一個關鍵設定值。 此功能My能提升登錄營運的生產力與效能。GetAllSettings 如需詳細資訊,請參閱Registry。
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static string? GetSetting(string AppName, string Section, string Key, string? Default = "");
public static string GetSetting(string AppName, string Section, string Key, string Default = "");
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetSetting : string * string * string * string -> string
static member GetSetting : string * string * string * string -> string
Public Function GetSetting (AppName As String, Section As String, Key As String, Optional Default As String = "") As String
參數
- AppName
- String
Required.
String 包含被請求的應用程式或專案名稱的表達式。
- Section
- String
Required.
String 包含該金鑰設定所在區段名稱的表達式。
- Key
- String
Required.
String 包含要回傳的鍵設定名稱的表達式。
- Default
- String
Optional. 包含若設定中未設定 Key 值時回傳的值的表達式。 若省略, Default 則假設為零長度字串(“”)。
傳回
來自應用程式在 Windows 登錄檔中條目的一個關鍵設定值。
此功能My能提升登錄營運的生產力與效能。GetAllSettings
- 屬性
例外狀況
一個或多個參數不是 String 表達式,或使用者未登入。
範例
本範例首先使用 SaveSetting 函式,在應用程式的 Windows 登錄檔中指定為 AppName,接著使用 GetSetting 函式顯示其中一個設定。 因為 Default 參數被指定,必然會回傳某個值。 請注意, Section 名稱無法用 GetSetting來檢索。 最後,函 DeleteSetting 式會移除應用程式的所有項目。
' 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")
備註
若參數中任何項目 GetSetting 不存在,則 GetSetting 回傳 值為 Default。
因為它是在 HKEY_LOCAL_USER 登錄檔金鑰下運作,登錄檔在使用者互動式登入前才會啟用,因此 GetSetting 必須使用者先登入。
要從非互動式程序(如 Mtx.exe)存取的登錄檔設定,應儲存在登錄檔金鑰或 HKEY_LOCAL_MACHINE\Software\ 登錄 HKEY_USER\DEFAULT\Software 檔金鑰下。
GetSetting 需要 ReadRegistryPermission。