RuntimeEnvironment 類別

定義

提供傳回 Common Language Runtime 環境的資訊之 static 方法的集合,。

public ref class RuntimeEnvironment abstract sealed
public ref class RuntimeEnvironment
public static class RuntimeEnvironment
public class RuntimeEnvironment
[System.Runtime.InteropServices.ComVisible(true)]
public class RuntimeEnvironment
type RuntimeEnvironment = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type RuntimeEnvironment = class
Public Class RuntimeEnvironment
繼承
RuntimeEnvironment
屬性

範例

此範例示範如何呼叫 類別所 RuntimeEnvironment 定義的許多方法。

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

int main()
{
    // Show whether the EXE assembly was loaded from the GAC or from a
    // private subdirectory.
    Console::WriteLine("Did the {0} assembly load from the GAC? {1}",
        Assembly::GetExecutingAssembly(),
        RuntimeEnvironment::FromGlobalAccessCache(
        Assembly::GetExecutingAssembly()));

    // Show the path where the CLR was loaded from.
    Console::WriteLine("Runtime directory: {0}",
        RuntimeEnvironment::GetRuntimeDirectory());

    // Show the CLR's version number.
    Console::WriteLine("System version: {0}",
        RuntimeEnvironment::GetSystemVersion());

    // Show the path of the machine's configuration file.
    Console::WriteLine("System configuration file: {0}",
        RuntimeEnvironment::SystemConfigurationFile);
}

// This code produces the following output.
//
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral,
// PublicKeyToken=null
// assembly load from the GAC? False
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
// System version: v2.0.40607
// System configuration file:
// C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\machine.config
using System;
using System.Reflection;
using System.Runtime.InteropServices;

public sealed class App
{
    static void Main()
    {
        // Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
        Assembly assem = typeof(App).Assembly;
        Console.WriteLine("Did the {0} assembly load from the GAC? {1}",
           assem, RuntimeEnvironment.FromGlobalAccessCache(assem));

        // Show the path where the CLR was loaded from.
        Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory());

        // Show the CLR's version number.
        Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion());

        // Show the path of the machine's configuration file.
        Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile);
    }
}

// This code produces the following output.
//
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// assembly load from the GAC? False
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
// System version: v2.0.40607
// System configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\
// machine.config
Imports System.Reflection
Imports System.Runtime.InteropServices

Public NotInheritable Class App
    Shared Sub Main()
        ' Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
        Dim assem As Assembly = GetType(App).Assembly
        Console.WriteLine("Did the {0} assembly load from the GAC? {1}", 
                          assem, RuntimeEnvironment.FromGlobalAccessCache(assem))
        ' Show the path where the CLR was loaded from.
        Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory())
        ' Show the CLR's version number.
        Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion())
        ' Show the path of the machine's configuration file.
        Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile)
    End Sub
End Class

' This code produces the following output.
'
' Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
' assembly load from the GAC? False
' Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
' System version: v2.0.40607
' System configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\
' machine.config

建構函式

RuntimeEnvironment()
已淘汰.

初始化 RuntimeEnvironment 類別的新執行個體。

屬性

SystemConfigurationFile
已淘汰.

取得系統組態檔的路徑。

方法

FromGlobalAccessCache(Assembly)

測試指定的組件是否會載入至全域組件快取。

GetRuntimeDirectory()

傳回安裝 Common Language Runtime 所在的目錄。

GetRuntimeInterfaceAsIntPtr(Guid, Guid)
已淘汰.

傳回指定類別上的指定介面。

GetRuntimeInterfaceAsObject(Guid, Guid)
已淘汰.

傳回型別的執行個體,用其 IUnknown 介面的指標來表示 COM 物件。

GetSystemVersion()

取得執行目前進程之 Common Language Runtime 的版本號碼。

適用於