WebConfigurationManager.OpenMachineConfiguration Metod

Definition

Öppnar datorkonfigurationsfilen som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

Överlagringar

Name Description
OpenMachineConfiguration()

Öppnar datorkonfigurationsfilen på den aktuella datorn som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

OpenMachineConfiguration(String)

Öppnar datorkonfigurationsfilen på den aktuella datorn som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

OpenMachineConfiguration(String, String)

Öppnar den angivna datorkonfigurationsfilen på den angivna servern som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

OpenMachineConfiguration(String, String, IntPtr)

Öppnar den angivna datorkonfigurationsfilen på den angivna servern som ett Configuration objekt med hjälp av den angivna säkerhetskontexten för att tillåta läs- eller skrivåtgärder.

OpenMachineConfiguration(String, String, String, String)

Öppnar den angivna datorkonfigurationsfilen på den angivna servern som ett Configuration objekt med hjälp av den angivna säkerhetskontexten för att tillåta läs- eller skrivåtgärder.

OpenMachineConfiguration()

Öppnar datorkonfigurationsfilen på den aktuella datorn som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

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

Returer

Ett Configuration objekt.

Undantag

Det gick inte att läsa in en giltig konfigurationsfil.

Exempel

I följande exempel visas hur du kommer åt konfigurationsinformation med OpenMachineConfiguration -metoden.


// 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

Kommentarer

Metoden OpenMachineConfiguration öppnar datorkonfigurationsfilen på datorn där programmet körs. Den här filen finns i standardversionskatalogen %windir%\Microsoft.NET\Framework\version\config.

Se även

Gäller för

OpenMachineConfiguration(String)

Öppnar datorkonfigurationsfilen på den aktuella datorn som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

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

Parametrar

locationSubPath
String

Den programsökväg som datorkonfigurationen gäller för.

Returer

Ett Configuration objekt.

Undantag

Det gick inte att läsa in en giltig konfigurationsfil.

Exempel

I följande exempel visas hur du kommer åt konfigurationsinformation med OpenMachineConfiguration -metoden.


// Show how to use OpenMachineConfiguration(string).
// It gets the machine.config file applicable to the
// specified resource and displays section
// basic information.
static void OpenMachineConfiguration2()
{
    // Get the machine.config file applicable to the
    // specified resource.
    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

Kommentarer

Den här metoden öppnar den datorkonfigurationsfil som gäller för den katalog som anges av parametern locationSubPath .

Se även

Gäller för

OpenMachineConfiguration(String, String)

Öppnar den angivna datorkonfigurationsfilen på den angivna servern som ett Configuration objekt för att tillåta läs- eller skrivåtgärder.

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

Parametrar

locationSubPath
String

Den programsökväg som konfigurationen gäller för.

server
String

Det fullständigt kvalificerade namnet på servern som konfigurationen ska returneras för.

Returer

Ett Configuration objekt.

Undantag

Det gick inte att läsa in en giltig konfigurationsfil.

Exempel

I följande exempel visas hur du kommer åt konfigurationsinformation med OpenMachineConfiguration -metoden.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server and
// applicable to the specified resource and displays section
// basic information.
static void OpenMachineConfiguration3()
{
    // Get the machine.config file applicable to the
    // specified resource 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

Kommentarer

Den här metoden öppnar den datorkonfigurationsfil som finns i katalogen som anges av parametern locationSubPath och på den dator som anges av parametern server .

Se även

Gäller för

OpenMachineConfiguration(String, String, IntPtr)

Öppnar den angivna datorkonfigurationsfilen på den angivna servern som ett Configuration objekt med hjälp av den angivna säkerhetskontexten för att tillåta läs- eller skrivåtgärder.

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

Parametrar

locationSubPath
String

Den programsökväg som konfigurationen gäller för.

server
String

Det fullständigt kvalificerade namnet på servern som konfigurationen ska returneras för.

userToken
IntPtr

nativeint

En kontotoken som ska användas.

Returer

Ett Configuration objekt.

Undantag

Giltiga värden angavs inte för parametrarna server eller userToken .

Det gick inte att läsa in en giltig konfigurationsfil.

Exempel

I följande exempel visas hur du kommer åt konfigurationsinformation med OpenMachineConfiguration -metoden.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicable to the specified resource, 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 applicable to the
    // specified resource, 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

Kommentarer

Den här metoden används för att komma åt en konfigurationsfil med personifiering.

Note

Kontotoken hämtas vanligtvis från en instans av klassen WindowsIdentity eller via ett anrop till ohanterad kod, till exempel ett anrop till Windows API LogonUser. Mer information om anrop till ohanterad kod finns i Använda ohanterade DLL-funktioner.

Se även

Gäller för

OpenMachineConfiguration(String, String, String, String)

Öppnar den angivna datorkonfigurationsfilen på den angivna servern som ett Configuration objekt med hjälp av den angivna säkerhetskontexten för att tillåta läs- eller skrivåtgärder.

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

Parametrar

locationSubPath
String

Den programsökväg som konfigurationen gäller för.

server
String

Det fullständigt kvalificerade namnet på servern som konfigurationen ska returneras för.

userName
String

Det fullständiga användarnamnet (domän\användare) som ska användas när filen öppnas.

password
String

Lösenordet för användarnamnet.

Returer

Ett Configuration objekt.

Undantag

Parametrarna server eller userName och password var ogiltiga.

Det gick inte att läsa in en giltig konfigurationsfil.

Exempel

I följande exempel visas hur du kommer åt konfigurationsinformation med OpenMachineConfiguration -metoden.


// Show how to use OpenMachineConfiguration(string, string).
// It gets the machine.config file on the specified server,
// applicable to the specified resource, 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 applicable to the
    // specified resource, 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

Kommentarer

Den här metoden används för att komma åt en konfigurationsfil med personifiering.

Se även

Gäller för