WebConfigurationManager.OpenMachineConfiguration メソッド

定義

マシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

オーバーロード

OpenMachineConfiguration()

現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

OpenMachineConfiguration(String)

現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

OpenMachineConfiguration(String, String)

指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

OpenMachineConfiguration(String, String, IntPtr)

セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

OpenMachineConfiguration(String, String, String, String)

セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

OpenMachineConfiguration()

現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

C#
public static System.Configuration.Configuration OpenMachineConfiguration ();

戻り値

Configuration オブジェクト。

例外

有効な構成ファイルを読み込むことができませんでした。

次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。

C#

// 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); 
}

注釈

メソッドは 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

OpenMachineConfiguration(String)

現在のコンピューター上のマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

C#
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath);

パラメーター

locationSubPath
String

マシン構成の適用先となるアプリケーション パス。

戻り値

Configuration オブジェクト。

例外

有効な構成ファイルを読み込むことができませんでした。

次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。

C#

// 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);
}

注釈

このメソッドは、 パラメーターで指定されたディレクトリに適用できるマシン構成ファイルを 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

OpenMachineConfiguration(String, String)

指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

C#
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server);

パラメーター

locationSubPath
String

構成の適用先となるアプリケーション パス。

server
String

構成を返すサーバーの完全修飾名。

戻り値

Configuration オブジェクト。

例外

有効な構成ファイルを読み込むことができませんでした。

次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。

C#

// 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);
}

注釈

このメソッドは、 パラメーターで指定されたディレクトリと、 パラメーターで 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

OpenMachineConfiguration(String, String, IntPtr)

セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

C#
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server, IntPtr userToken);

パラメーター

locationSubPath
String

構成の適用先となるアプリケーション パス。

server
String

構成を返すサーバーの完全修飾名。

userToken
IntPtr

使用するアカウント トークン。

戻り値

Configuration オブジェクト。

例外

有効な値が server パラメーターまたは userToken パラメーターに指定されていませんでした。

有効な構成ファイルを読み込むことができませんでした。

次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。

C#

// 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);
}

注釈

このメソッドは、偽装を使用して構成ファイルにアクセスするために使用されます。

注意

アカウント トークンは、通常、 クラスの 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

OpenMachineConfiguration(String, String, String, String)

セキュリティ コンテキストを使用して、指定したサーバー上の指定したマシン構成ファイルを Configuration オブジェクトとして開き、読み取りまたは書き込みができるようにします。

C#
public static System.Configuration.Configuration OpenMachineConfiguration (string locationSubPath, string server, string userName, string password);

パラメーター

locationSubPath
String

構成の適用先となるアプリケーション パス。

server
String

構成を返すサーバーの完全修飾名。

userName
String

ファイルを開く際に使用する完全なユーザー名 (Domain\User)。

password
String

該当するユーザー名のパスワード。

戻り値

Configuration オブジェクト。

例外

server パラメーターが無効か、userName パラメーターと password パラメーターが無効でした。

有効な構成ファイルを読み込むことができませんでした。

次の例は、 メソッドを使用して構成情報にアクセスする方法を OpenMachineConfiguration 示しています。

C#

// 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);
}

注釈

このメソッドは、偽装を使用して構成ファイルにアクセスするために使用されます。

こちらもご覧ください

適用対象

.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