获取当前的ClickOnce的应用程序发布者的名称? [英] Get current ClickOnce's application publisher name?
问题描述
是否可以读取当前运行ClickOnce应用程序的发布者的名称(你的设置项目属性之一 - >发布 - >选项 - >发布者的名称
在Visual Studio)?
Is it possible to read the publisher name of the currently running ClickOnce application (the one you set at Project Properties -> Publish -> Options -> Publisher name
in Visual Studio)?
我之所以需要它是如这文章,并传递参数给它。
The reason why I need it is to run another instance of the currently running application as described in this article and pass parameters to it.
当然,我的知道的我的应用程序的发布者的名字,但如果我硬code它,后来我决定改变我的出版商的名字我将最有可能忘记更新这块$的C $℃。
Of course I do know my application's publisher name, but if I hard code it and later on I decide to change my publisher's name I will most likely forget to update this piece of code.
推荐答案
您会认为这将是微不足道的,但我没有看到,让你这个信息框架事情。
You would think this would be trivial, but I don't see anything in the framework that gives you this info.
如果你想有一个黑客,你可以从注册表中的发布者。
If you want a hack, you can get the publisher from the registry.
免责声明 - code是丑陋的和未经考验......
Disclaimer - Code is ugly and untested...
...
var publisher = GetPublisher("My App Name");
...
public static string GetPublisher(string application)
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall"))
{
var appKey = key.GetSubKeyNames().FirstOrDefault(x => GetValue(key, x, "DisplayName") == application);
if (appKey == null) { return null; }
return GetValue(key, appKey, "Publisher");
}
}
private static string GetValue(RegistryKey key, string app, string value)
{
using (var subKey = key.OpenSubKey(app))
{
if (!subKey.GetValueNames().Contains(value)) { return null; }
return subKey.GetValue(value).ToString();
}
}
如果你找到一个更好的解决方案,请跟进。
If you find a better solution, please follow-up.
这篇关于获取当前的ClickOnce的应用程序发布者的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!