Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

clickonce

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 unmanaged 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.

like image 708
tofutim Avatar asked Jun 16 '11 19:06

tofutim


1 Answers

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.

like image 116
J Cooper Avatar answered Oct 11 '22 14:10

J Cooper