ConfigurationManager.OpenExeConfiguration メソッド (ConfigurationUserLevel)
アセンブリ: System.Configuration (system.configuration.dll 内)

Public Shared Function OpenExeConfiguration ( _ userLevel As ConfigurationUserLevel _ ) As Configuration
Dim userLevel As ConfigurationUserLevel Dim returnValue As Configuration returnValue = ConfigurationManager.OpenExeConfiguration(userLevel)
public static Configuration OpenExeConfiguration ( ConfigurationUserLevel userLevel )
public: static Configuration^ OpenExeConfiguration ( ConfigurationUserLevel userLevel )
public static Configuration OpenExeConfiguration ( ConfigurationUserLevel userLevel )
public static function OpenExeConfiguration ( userLevel : ConfigurationUserLevel ) : Configuration
戻り値
Configuration オブジェクト。


クライアント アプリケーションでは、すべてのユーザーに適用するグローバル構成、個々のユーザーに適用する個別構成、およびローミング ユーザーに適用する構成を使用します。userLevel パラメータは、構成ファイルがユーザー レベルではない (構成ファイルがアプリケーションと同じディレクトリにある)、またはユーザー単位のレベル (構成ファイルがユーザー レベルで決まるアプリケーション設定のパスにある) のどちらであるかを示すことによって、開く構成ファイルの場所を決定します。
userLevel の次の値のいずれかを渡すことによって、取得する構成を指定します。
-
すべてのユーザーに適用する Configuration オブジェクトを取得するには、userLevel に None を設定します。
-
現在のユーザーに適用するローカル Configuration オブジェクトを取得するには、userLevel に PerUserRoamingAndLocal を設定します。
-
現在のユーザーに適用するローミング Configuration オブジェクトを取得するには、userLevel に PerUserRoaming を設定します。
メモ
リソースの Configuration オブジェクトを取得するには、設定の継承元となるすべての構成ファイルに対する読み取り特権がコードに付与されている必要があります。構成ファイルを更新するには、構成ファイルとそれを格納するディレクトリの両方に対する書き込み特権も、コードに付与されている必要があります。

OpenExeConfiguration メソッドを使用して、カスタム構成セクションを変更する方法を次のコード例に示します。
' Modify a custom section. Show how to use the ' OpenExeConfiguration(ConfigurationUserLevel) method. Shared Sub ModifyCustomSection() ' Get the application configuration file. Dim config As System.Configuration.Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) Console.WriteLine(config.FilePath) Dim custSection As CustomSection = _ config.Sections(customSectionName) custSection.FileName = "newName.txt" custSection.MaxIdleTime = New TimeSpan(0, 15, 0) custSection.MaxUsers = custSection.MaxUsers + 10 If Not custSection.ElementInformation.IsLocked Then config.Save() Else Console.WriteLine("Section was locked, could not update.") End If End Sub 'ModifyCustomSection
// Modify a custom section. Show how to use the // OpenExeConfiguration(ConfigurationUserLevel) method. static void ModifyCustomSection() { // Get the application configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); Console.WriteLine(config.FilePath); CustomSection custSection = config.Sections[customSectionName] as CustomSection; custSection.FileName = "newName.txt"; custSection.MaxIdleTime = new TimeSpan(0, 15, 0); custSection.MaxUsers = custSection.MaxUsers + 10; if (!custSection.ElementInformation.IsLocked) config.Save(); else Console.WriteLine("Section was locked, could not update."); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ConfigurationManager クラス
ConfigurationManager メンバ
System.Configuration 名前空間
ConfigurationUserLevel
Configuration クラス
ConfigurationManager.OpenExeConfiguration メソッド (String)
アセンブリ: System.Configuration (system.configuration.dll 内)

Public Shared Function OpenExeConfiguration ( _ exePath As String _ ) As Configuration
Dim exePath As String Dim returnValue As Configuration returnValue = ConfigurationManager.OpenExeConfiguration(exePath)
public static Configuration OpenExeConfiguration ( string exePath )
public: static Configuration^ OpenExeConfiguration ( String^ exePath )
public static Configuration OpenExeConfiguration ( String exePath )
戻り値
Configuration オブジェクト。


クライアント アプリケーションでは、すべてのユーザーに適用するグローバル構成、個々のユーザーに適用する個別構成、およびローミング ユーザーに適用する構成を使用します。userLevel 値は、構成ファイルがユーザー レベルではない (構成ファイルがアプリケーションと同じディレクトリにある)、またはユーザー単位のレベル (構成ファイルがユーザー レベルの種類で決まるアプリケーション設定のパスにある) のどちらであるかを示すことによって、開く構成ファイルの場所を決定します。
userLevel パラメータの次の値のいずれかを渡すことによって、取得する構成を指定します。
-
すべてのユーザーに適用する Configuration を取得するには、userLevel に None を設定します。
-
現在のユーザーに適用するローカル Configuration を取得するには、userLevel に PerUserRoamingAndLocal を設定します。
-
現在のユーザーに適用するローミング Configuration を取得するには、userLevel に PerUserRoaming を設定します。
メモ
リソースの Configuration オブジェクトを取得するには、設定の継承元となるすべての構成ファイルに対する読み取り特権がコードに付与されている必要があります。構成ファイルを更新するには、構成ファイルとそれを格納するディレクトリの両方に対する書き込み特権も、コードに付与されている必要があります。

OpenExeConfiguration メソッドを使用して、カスタム構成セクションを変更する方法を次のコード例に示します。
' Modify a custom section. ' Show how to use the ' OpenExeConfiguration(ConfigurationUserLevel, ' config file path) method. Shared Sub ModifyCustomSection2() ' Get the application configuration file. Dim config As System.Configuration.Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) Dim custSection As CustomSection = _ config.Sections(customSectionName) custSection.FileName = "anotherName.txt" custSection.MaxIdleTime = New TimeSpan(0, 20, 0) custSection.MaxUsers = custSection.MaxUsers + 20 If Not custSection.ElementInformation.IsLocked Then config.Save() Else Console.WriteLine("Section was locked, could not update.") End If End Sub 'ModifyCustomSection2
// Modify a custom section. // Show how to use the // OpenExeConfiguration(ConfigurationUserLevel, // config file path) method. static void ModifyCustomSection2() { // Get the application configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); CustomSection custSection = config.Sections[customSectionName] as CustomSection; custSection.FileName = "anotherName.txt"; custSection.MaxIdleTime = new TimeSpan(0, 20, 0); custSection.MaxUsers = custSection.MaxUsers + 20; if (!custSection.ElementInformation.IsLocked) config.Save(); else Console.WriteLine("Section was locked, could not update."); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ConfigurationManager クラス
ConfigurationManager メンバ
System.Configuration 名前空間
ConfigurationUserLevel
Configuration クラス
ConfigurationManager.OpenExeConfiguration メソッド

名前 | 説明 |
---|---|
ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel) | 現在のアプリケーションの構成ファイルを Configuration オブジェクトとして開きます。 |
ConfigurationManager.OpenExeConfiguration (String) | 指定したクライアント構成ファイルを Configuration オブジェクトとして開きます。 |

関連項目
ConfigurationManager クラスConfigurationManager メンバ
System.Configuration 名前空間
ConfigurationUserLevel
Configuration クラス
- ConfigurationManager.OpenExeConfigurationのページへのリンク