ConfigurationManager.OpenMachineConfiguration 메서드

정의

현재 컨퓨터의 컴퓨터 구성 파일을 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

반환

컴퓨터 구성 파일입니다.

예외

구성 파일을 로드할 수 없는 경우

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 OpenMachineConfiguration 구성 파일에 포함 된 모든 섹션을 가져오는 방법입니다.

   // Access the machine configuration file using mapping.
   // The function uses the OpenMappedMachineConfiguration 
   // method to access the machine configuration. 
   public static void MapMachineConfiguration()
   {
     // Get the machine.config file.
     Configuration machineConfig =
       ConfigurationManager.OpenMachineConfiguration();
     // Get the machine.config file path.
     ConfigurationFileMap configFile =
       new ConfigurationFileMap(machineConfig.FilePath);

     // Map the application configuration file to the machine 
     // configuration file.
     Configuration config =
       ConfigurationManager.OpenMappedMachineConfiguration(
         configFile);

     // Get the AppSettings section.
     AppSettingsSection appSettingSection =
       (AppSettingsSection)config.GetSection("appSettings");
     appSettingSection.SectionInformation.AllowExeDefinition =
         ConfigurationAllowExeDefinition.MachineToRoamingUser;

     // Display the configuration file sections.
     ConfigurationSectionCollection sections = 
       config.Sections;

     Console.WriteLine();
     Console.WriteLine("Using OpenMappedMachineConfiguration.");
     Console.WriteLine("Sections in machine.config:");

     // Get the sections in the machine.config.
     foreach (ConfigurationSection section in sections)
     {
         string name = section.SectionInformation.Name;
         Console.WriteLine("Name: {0}", name);
     }
   }
' Access the machine configuration file using mapping.
' The function uses the OpenMappedMachineConfiguration 
' method to access the machine configuration. 
Public Shared Sub MapMachineConfiguration()
    ' Get the machine.config file.
    Dim machineConfig As Configuration = _
        ConfigurationManager.OpenMachineConfiguration()
    ' Get the machine.config file path.
    Dim configFile _
        As New ConfigurationFileMap( _
            machineConfig.FilePath)

    ' Map the application configuration file 
    ' to the machine configuration file.
    Dim config As Configuration = _
        ConfigurationManager. _
        OpenMappedMachineConfiguration( _
            configFile)

    ' Get the AppSettings section.
    Dim appSettingSection As AppSettingsSection = _
        DirectCast(config.GetSection("appSettings"),  _
            AppSettingsSection)
    appSettingSection.SectionInformation. _
    AllowExeDefinition = _
        ConfigurationAllowExeDefinition. _
        MachineToRoamingUser

    ' Display the configuration file sections.
    Dim sections As  _
        ConfigurationSectionCollection = _
        config.Sections

    Console.WriteLine()
    Console.WriteLine( _
        "Using OpenMappedMachineConfiguration.")
    Console.WriteLine( _
        "Sections in machine.config:")

    ' Get the sections in the machine.config.
    For Each section _
        As ConfigurationSection In sections
        Dim name As String = _
            section.SectionInformation.Name
        Console.WriteLine("Name: {0}", name)
    Next

End Sub

설명

컴퓨터 구성 설정은 로컬 애플리케이션에 대 한 재정의 되지 않은 경우 전체 컴퓨터에 있는 모든 애플리케이션에 적용 됩니다. 컴퓨터 구성 설정은 현재 실행 중인 .NET Framework 버전의 Machine.config 파일에서 읽습니다. Machine.config 파일은 다음 하위 디렉터리에 있습니다.

%windir%\Microsoft.NET\Framework\version\config

참고

리소스에 대한 개체를 Configuration 가져오려면 코드에 설정을 상속하는 모든 구성 파일에 대한 읽기 권한이 있어야 합니다. 구성 파일을 업데이트하려면 코드에 구성 파일과 해당 파일이 있는 디렉터리에 대한 쓰기 권한이 추가로 있어야 합니다. 컴퓨터에 설치될 수 있는 다른 버전의 .NET Framework Machine.config 파일에 액세스할 수 없습니다.

적용 대상

추가 정보