WebConfigurationManager.OpenMachineConfiguration メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
マシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
OpenMachineConfiguration() |
現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。 |
OpenMachineConfiguration(String) |
現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。 |
OpenMachineConfiguration(String, String) |
指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。 |
OpenMachineConfiguration(String, String, IntPtr) |
セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。 |
OpenMachineConfiguration(String, String, String, String) |
セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。 |
現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
public:
static System::Configuration::Configuration ^ OpenMachineConfiguration();
public static System.Configuration.Configuration OpenMachineConfiguration ();
static member OpenMachineConfiguration : unit -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration () As Configuration
戻り値
Configuration オブジェクト。
例外
有効な構成ファイルを読み込むことができませんでした。
例
次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。
// Show how to use OpenMachineConfiguration().
// It gets the machine.config file on the current
// machine and displays section information.
static void OpenMachineConfiguration1()
{
// Get the machine.config file on the current machine.
System.Configuration.Configuration config =
WebConfigurationManager.OpenMachineConfiguration();
// Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition");
int i = 0;
foreach (ConfigurationSection section in config.Sections)
{
Console.WriteLine(
section.SectionInformation.Name + "\t" +
section.SectionInformation.AllowExeDefinition);
i += 1;
}
Console.WriteLine("[Total number of sections: {0}]", i);
// Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration().
' It gets the machine.config file on the current
' machine and displays section information.
Shared Sub OpenMachineConfiguration1()
' Get the machine.config file on the current machine.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenMachineConfiguration()
' Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition")
Dim i As Integer = 0
Dim section As ConfigurationSection
For Each section In config.Sections
Console.WriteLine((section.SectionInformation.Name + _
ControlChars.Tab + _
section.SectionInformation.AllowExeDefinition.ToString()))
i += 1
Next section
Console.WriteLine("[Total number of sections: {0}]", i)
' Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub
注釈
メソッドは OpenMachineConfiguration 、アプリケーションが実行されているコンピューター上のコンピューター構成ファイルを開きます。 このファイルは、標準のビルド ディレクトリ %windir%\Microsoft.NET\Framework\version\config にあります。
こちらもご覧ください
適用対象
.NET Framework 4.8.1 およびその他のバージョン
製品 | バージョン |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
public:
static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath);
static member OpenMachineConfiguration : string -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String) As Configuration
パラメーター
- locationSubPath
- String
マシン構成の適用先となるアプリケーション パス。
戻り値
Configuration オブジェクト。
例外
有効な構成ファイルを読み込むことができませんでした。
例
次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。
// Show how to use OpenMachineConfiguration(string).
// It gets the machine.config file applicabe to the
// specified resource and displays section
// basic information.
static void OpenMachineConfiguration2()
{
// Get the machine.config file applicabe to the
// specified reosurce.
System.Configuration.Configuration config =
WebConfigurationManager.OpenMachineConfiguration("configTest");
// Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition");
int i = 0;
foreach (ConfigurationSection section in config.Sections)
{
Console.WriteLine(
section.SectionInformation.Name + "\t" +
section.SectionInformation.AllowExeDefinition);
i += 1;
}
Console.WriteLine("[Total number of sections: {0}]", i);
// Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string).
' It gets the machine.config file applicabe to the
' specified resource and displays section
' basic information.
Shared Sub OpenMachineConfiguration2()
' Get the machine.config file applicabe to the
' specified reosurce.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenMachineConfiguration( _
"configTest")
' Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition")
Dim i As Integer = 0
Dim section As ConfigurationSection
For Each section In config.Sections
Console.WriteLine((section.SectionInformation.Name + _
ControlChars.Tab + _
section.SectionInformation.AllowExeDefinition.ToString()))
i += 1
Next section
Console.WriteLine("[Total number of sections: {0}]", i)
' Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub
注釈
このメソッドは、 パラメーターで指定されたディレクトリに適用できるマシン構成ファイルを locationSubPath
開きます。
こちらもご覧ください
適用対象
.NET Framework 4.8.1 およびその他のバージョン
製品 | バージョン |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
public:
static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath, System::String ^ server);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server);
static member OpenMachineConfiguration : string * string -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String, server As String) As Configuration
パラメーター
- locationSubPath
- String
構成の適用先となるアプリケーション パス。
- server
- String
構成を返すサーバーの完全修飾名。
戻り値
Configuration オブジェクト。
例外
有効な構成ファイルを読み込むことができませんでした。
例
次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。
// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server and
// applicabe to the specified reosurce and displays section
// basic information.
static void OpenMachineConfiguration3()
{
// Get the machine.config file applicabe to the
// specified reosurce and on the specified server.
System.Configuration.Configuration config =
WebConfigurationManager.OpenMachineConfiguration("configTest",
"myServer");
// Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition");
int i = 0;
foreach (ConfigurationSection section in config.Sections)
{
Console.WriteLine(
section.SectionInformation.Name + "\t" +
section.SectionInformation.AllowExeDefinition);
i += 1;
}
Console.WriteLine("[Total number of sections: {0}]", i);
// Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string, string).
' It gets the machine.config file on the specified server and
' applicabe to the specified reosurce and displays section
' basic information.
Shared Sub OpenMachineConfiguration3()
' Get the machine.config file applicabe to the
' specified reosurce and on the specified server.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenMachineConfiguration( _
"configTest", "myServer")
' Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition")
Dim i As Integer = 0
Dim section As ConfigurationSection
For Each section In config.Sections
Console.WriteLine((section.SectionInformation.Name + _
ControlChars.Tab + _
section.SectionInformation.AllowExeDefinition.ToString()))
i += 1
Next section
Console.WriteLine("[Total number of sections: {0}]", i)
' Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub
注釈
このメソッドは、 パラメーターで指定されたディレクトリと、 パラメーターで locationSubPath
指定されたコンピューター上にあるコンピューター構成ファイルを server
開きます。
こちらもご覧ください
適用対象
.NET Framework 4.8.1 およびその他のバージョン
製品 | バージョン |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
public:
static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath, System::String ^ server, IntPtr userToken);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server, IntPtr userToken);
static member OpenMachineConfiguration : string * string * nativeint -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String, server As String, userToken As IntPtr) As Configuration
パラメーター
- locationSubPath
- String
構成の適用先となるアプリケーション パス。
- server
- String
構成を返すサーバーの完全修飾名。
- userToken
-
IntPtr
nativeint
使用するアカウント トークン。
戻り値
Configuration オブジェクト。
例外
有効な値が server
パラメーターまたは userToken
パラメーターに指定されていませんでした。
有効な構成ファイルを読み込むことができませんでした。
例
次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。
// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicabe to the specified reosurce, for the specified user
// and displays section basic information.
static void OpenMachineConfiguration4()
{
// Get the current user token.
IntPtr userToken =
System.Security.Principal.WindowsIdentity.GetCurrent().Token;
// Get the machine.config file applicabe to the
// specified reosurce, on the specified server for the
// specified user.
System.Configuration.Configuration config =
WebConfigurationManager.OpenMachineConfiguration("configTest",
"myServer", userToken);
// Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition");
int i = 0;
foreach (ConfigurationSection section in config.Sections)
{
Console.WriteLine(
section.SectionInformation.Name + "\t" +
section.SectionInformation.AllowExeDefinition);
i += 1;
}
Console.WriteLine("[Total number of sections: {0}]", i);
// Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string, string).
' It gets the machine.config file on the specified server,
' applicabe to the specified reosurce, for the specified user
' and displays section basic information.
Shared Sub OpenMachineConfiguration4()
' Get the current user token.
Dim userToken As IntPtr = _
System.Security.Principal.WindowsIdentity.GetCurrent().Token
' Get the machine.config file applicabe to the
' specified reosurce, on the specified server for the
' specified user.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenMachineConfiguration( _
"configTest", "myServer", userToken)
' Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition")
Dim i As Integer = 0
Dim section As ConfigurationSection
For Each section In config.Sections
Console.WriteLine((section.SectionInformation.Name + _
ControlChars.Tab + _
section.SectionInformation.AllowExeDefinition.ToString()))
i += 1
Next section
Console.WriteLine("[Total number of sections: {0}]", i)
' Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub
注釈
このメソッドは、偽装を使用して構成ファイルにアクセスするために使用されます。
注意
アカウント トークンは、通常、 クラスの WindowsIdentity インスタンスから、または Windows API LogonUser
の呼び出しなどのアンマネージ コードの呼び出しを介して取得されます。 アンマネージド コードの呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。
こちらもご覧ください
適用対象
.NET Framework 4.8.1 およびその他のバージョン
製品 | バージョン |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。
public:
static System::Configuration::Configuration ^ OpenMachineConfiguration(System::String ^ locationSubPath, System::String ^ server, System::String ^ userName, System::String ^ password);
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server, string userName, string password);
static member OpenMachineConfiguration : string * string * string * string -> System.Configuration.Configuration
Public Shared Function OpenMachineConfiguration (locationSubPath As String, server As String, userName As String, password As String) As Configuration
パラメーター
- locationSubPath
- String
構成の適用先となるアプリケーション パス。
- server
- String
構成を返すサーバーの完全修飾名。
- userName
- String
ファイルを開く際に使用する完全なユーザー名 (Domain\User)。
- password
- String
該当するユーザー名のパスワード。
戻り値
Configuration オブジェクト。
例外
server
パラメーターが無効か、userName
パラメーターと password
パラメーターが無効でした。
有効な構成ファイルを読み込むことができませんでした。
例
次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。
// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicabe to the specified reosurce, for the specified user
// and displays section basic information.
static void OpenMachineConfiguration5()
{
// Set the user id and password.
string user =
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// Substitute with actual password.
string password = "userPassword";
// Get the machine.config file applicabe to the
// specified reosurce, on the specified server for the
// specified user.
System.Configuration.Configuration config =
WebConfigurationManager.OpenMachineConfiguration("configTest",
"myServer", user, password);
// Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition");
int i = 0;
foreach (ConfigurationSection section in config.Sections)
{
Console.WriteLine(
section.SectionInformation.Name + "\t" +
section.SectionInformation.AllowExeDefinition);
i += 1;
}
Console.WriteLine("[Total number of sections: {0}]", i);
// Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath);
}
' Show how to use OpenMachineConfiguration(string, string).
' It gets the machine.config file on the specified server,
' applicabe to the specified reosurce, for the specified user
' and displays section basic information.
Shared Sub OpenMachineConfiguration5()
' Set the user id and password.
Dim user As String = _
System.Security.Principal.WindowsIdentity.GetCurrent().Name
' Substitute with actual password.
Dim password As String = "userPassword"
' Get the machine.config file applicabe to the
' specified reosurce, on the specified server for the
' specified user.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenMachineConfiguration( _
"configTest", "myServer", user, password)
' Loop to get the sections. Display basic information.
Console.WriteLine("Name, Allow Definition")
Dim i As Integer = 0
Dim section As ConfigurationSection
For Each section In config.Sections
Console.WriteLine((section.SectionInformation.Name + _
ControlChars.Tab + _
section.SectionInformation.AllowExeDefinition.ToString()))
i += 1
Next section
Console.WriteLine("[Total number of sections: {0}]", i)
' Display machine.config path.
Console.WriteLine("[File path: {0}]", config.FilePath)
End Sub
注釈
このメソッドは、偽装を使用して構成ファイルにアクセスするために使用されます。
こちらもご覧ください
適用対象
.NET Framework 4.8.1 およびその他のバージョン
製品 | バージョン |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。