Share via


SaveSetting 函式

更新:2007 年 11 月

在 Windows 登錄中儲存或建立應用程式項目。

My 函式在登錄作業中的產能和效能勝過 SaveSetting。如需詳細資訊,請參閱 My.Computer.Registry 物件

Public Sub SaveSetting( _
   ByVal AppName As String, _ 
   ByVal Section As String, _
   ByVal Key As String, _
   ByVal Setting As String _
)

參數

  • AppName
    必要項。String 運算式,包含應用程式名稱或是設定所套用的專案名稱。

  • Section
    必要項。String 運算式,包含要儲存機碼設定所在的區段名稱。

  • Key
    必要項。String 運算式,包含要儲存的機碼設定名稱。

  • Setting
    必要項。運算式,包含 Key 要設定的值。

例外狀況

例外狀況類型

錯誤代碼

條件

ArgumentException

5

無法建立登錄機碼或使用者未登入。

如果將使用非結構化錯誤處理的 Visual Basic 6.0 應用程式升級,請參閱「錯誤代碼」資料行 (您可以將錯誤代碼與 Number 屬性 (Err 物件) 比對)。但是,請盡可能考慮以 Visual Basic 的結構化例外處理概觀 取代這類錯誤控制項。

備註

SaveSetting 函式會將機碼加入至 HKEY_CURRENT_USER\Software\VB and VBA Program Settings。

如果無法儲存機碼設定,則會發生錯誤。

因為 SaveSetting 是在 HKEY_LOCAL_USER 登錄機碼 (Registry Key) 下作業,所以它會要求使用者登入,而這個機碼要等到使用者以互動方式登入時才會作用。

要從非互動式處理序 (例如 Mtx.exe) 存取的登錄設定應該存放在 HKEY_LOCAL_MACHINE\Software\ 或 HKEY_USER\DEFAULT\Software 登錄機碼 (Registry Key) 之下。

SaveSetting 需要 Write 和 Create登錄使用權限

範例

下列範例會先使用 SaveSetting 函式在 Windows 登錄中為 MyApp 應用程式建立項目,然後使用 DeleteSetting 函式來移除它們。

' 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")

智慧型裝置開發人員注意事項

不支援這個函式。

需求

命名空間 (Namespace)︰Microsoft.VisualBasic

**模組︰**Interaction

組件:Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

概念

一般登錄工作

參考

DeleteSetting 函式

GetAllSettings 函式

GetSetting 函式

RegistryPermission