开发者

How do I set the AppDomain FriendlyName in a ClickOnce scenario?

It seems that the FriendlyName gets set to "DefaultDomain" when the application is deployed using ClickOnce instead of the exe name. I would like to disambiguate my windows from other potential ClickOnce apps that may also be "DefaultDomain".

Clarification: We are using an unmana开发者_如何转开发ged call,

[DllImport("user32.dll")]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

to retrieve the class name of windows around the user's desktop, and need to make sure we respond in a certain way to windows created by our application. When deployed by ClickOnce, our windows no longer carry the exe name as the domain and will not be easily distinguished from other potential ClickOnce deployed apps.


Great Question.

I can't say for sure why this is the case, but I believe that perhaps the application is 'hosted' differently since it is the 'ClickOnce Application Deployment Support Library' that is launching the application.

However, if you have an unrelenting desire to use AppDomain.FriendlyName to distinguish your applications, then perhaps you could create the appdomain yourself and define your own friendly name.

Another idea that would serve the same purpose would be to to use the application full name as follows:

private static string GetAppName()
{
    if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
    {

        ApplicationDeployment curDeployment = ApplicationDeployment.CurrentDeployment;
        string fullname = curDeployment.UpdatedApplicationFullName;
        Match match = Regex.Match(fullname, "#.+/(?<app>.+).exe");

        return match.Groups["app"].ToString();
    }
    return null;
}

I created the regex pretty quickly, so no gurantees. Here is a link that explains the naming conventions: http://blogs.msdn.com/b/shawnfa/archive/2004/06/30/170241.aspx

Another idea would be to just use reflection to get the calling assembly name, but this will not work so well in all partial-trust environments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜