Export (0) Print
Expand All

ConfigurationManager.OpenMachineConfiguration Method

Note: This method is new in the .NET Framework version 2.0.

Opens the machine configuration file on the current computer as a Configuration object.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

public static Configuration OpenMachineConfiguration ()
public static Configuration OpenMachineConfiguration ()
public static function OpenMachineConfiguration () : Configuration

Return Value

A Configuration object.

Exception typeCondition


A configuration file could not be loaded.

Machine configuration settings apply to the entire computer and all applications that reside on it, unless overridden for the local application. Machine configuration settings are read from the Machine.config file of the currently running version of the .NET Framework. The Machine.config file is located in the following subdirectory:



To obtain the Configuration object for a resource, your code must have read privileges on all of the configuration files from which it inherits settings. To update a configuration file, your code must additionally have write privileges for both the configuration file and the directory in which it exists. It is not possible to access the Machine.config file for other versions of the .NET Framework that might be installed on the computer.

The following code example shows how to use the OpenMachineConfiguration method to obtain all sections contained in the configuration file.

// Get all the sections in machine.config.
// Show how to use the OpenMachineConfiguration method.
static void GetMachineSections()
    // Get the machine.config file.
    System.Configuration.Configuration config =

    // Loop to get the sections. Display basic information.
    Console.WriteLine("Name, Allow Definition");
    int i = 0;
    foreach (ConfigurationSection section in config.Sections)
            section.SectionInformation.Name + "\t" +
        i += 1;

    Console.WriteLine("[Total number of sections: {0]", i);

    // Display machine.config path.
    Console.WriteLine("[File path: {0]", config.FilePath); 

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft