从应用程序域中检索安装程序信息
更新:2007 年 11 月
应用程序域的每个实例同时包含属性和 AppDomainSetup 信息。您可以使用 System.AppDomain 类从应用程序域中检索安装信息。此类提供了几个检索有关应用程序域的配置信息的成员。
您也可以查询应用程序域的 AppDomainSetup 对象,获取创建该对象时传递至域的安装信息。
下面的示例创建新的应用程序域,然后将几个成员值输出至控制台。
Imports System
Imports System.Reflection
Class AppDomain3
Public Shared Sub Main()
'Create the new application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing)
'Output to the console.
Console.WriteLine(("Host domain: " + AppDomain.CurrentDomain.FriendlyName))
Console.WriteLine(("new domain: " + domain.FriendlyName))
Console.WriteLine(("Application base is: " + domain.BaseDirectory))
Console.WriteLine(("Relative search path is: " + domain.RelativeSearchPath))
Console.WriteLine(("Shadow copy files is set to: " + domain.ShadowCopyFiles))
AppDomain.Unload(domain)
End Sub 'Main
End Class 'AppDomain3
using System;
using System.Reflection;
class AppDomain3
{
public static void Main()
{
//Create the new application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null);
//Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("new domain: " + domain.FriendlyName);
Console.WriteLine("Application base is: " + domain.BaseDirectory);
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath);
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles);
AppDomain.Unload(domain);
}
}
下面的示例设置并检索应用程序域的安装信息。请注意,AppDomain.SetupInformation.ApplicationBase 获取配置信息。
Imports System
Imports System.Reflection
Class AppDomain5
Public Shared Sub Main()
' Application domain setup information.
Dim domaininfo As New AppDomainSetup()
domaininfo.ApplicationBase = "f:\work\development\latest"
domaininfo.ConfigurationFile = "f:\work\development\latest\appdomain5.exe.config"
' Creates the application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, domaininfo)
' Write the application domain information to the console.
Console.WriteLine(("Host domain: " + AppDomain.CurrentDomain.FriendlyName))
Console.WriteLine(("child domain: " + domain.FriendlyName))
Console.WriteLine()
Console.WriteLine(("Application base is: " + domain.SetupInformation.ApplicationBase))
Console.WriteLine(("Configuration file is: " + domain.SetupInformation.ConfigurationFile))
' Unloads the application domain.
AppDomain.Unload(domain)
End Sub 'Main
End Class 'AppDomain5
using System;
using System.Reflection;
class AppDomain5
{
public static void Main()
{
// Application domain setup information.
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = "f:\\work\\development\\latest";
domaininfo.ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null, domaininfo);
// Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("child domain: " + domain.FriendlyName);
Console.WriteLine();
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase);
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile);
// Unloads the application domain.
AppDomain.Unload(domain);
}
}