简体   繁体   English

访问有关clickonce应用程序的文件夹信息

[英]Accessing folder information about clickonce application

Here's the problem: 这是问题所在:

I have two applications. 我有两个应用程序。 One of them is a clickonce application that I do not have access to, and the other one is ac# program I'm designing. 其中一个是我无法访问的clickonce应用程序,另一个是我正在设计的ac#程序。 I need a way to track down the application folder where the app is installed by either the .appref-ms file in the start menu, or the token id/name found from within that file. 我需要一种通过开始菜单中的.appref-ms文件或从该文件中找到的令牌ID /名称来跟踪应用程序安装位置的应用程序文件夹的方法。

Is this possible? 这可能吗? Is there a way to query the clickonce store for a list of applications and where they are installed to? 是否可以查询clickonce商店以获取应用程序列表以及它们的安装位置? Everything I have found refers to opening the process list and going to the process image location, but this is not possible if the program is not running. 我发现的所有内容都涉及打开过程列表并转到过程映像位置,但是如果程序未运行,则无法实现。

ClickOnce store data in Windows registry key: HKEY_CURRENT_USER\\Software\\Classes\\Software\\Microsoft\\Windows\\CurrentVersion\\Deployment ClickOnce将数据存储在Windows注册表项中: HKEY_CURRENT_USER\\Software\\Classes\\Software\\Microsoft\\Windows\\CurrentVersion\\Deployment

Registry key with application list: HKEY_CURRENT_USER\\Software\\Classes\\Software\\Microsoft\\Windows\\CurrentVersion\\Deployment\\SideBySide\\2.0\\StateManager\\Applications 带有应用程序列表的注册表项: HKEY_CURRENT_USER\\Software\\Classes\\Software\\Microsoft\\Windows\\CurrentVersion\\Deployment\\SideBySide\\2.0\\StateManager\\Applications

I don't know a way to query the ClickOnce store. 我不知道查询ClickOnce商店的方法。

But as @Vojtěch Dohnal said. 但是正如@VojtěchDohnal所说。 All ClickOnce applicaitons will be stored in C:\\Users\\xxxx\\AppData\\Local\\Apps\\2.0 所有ClickOnce应用程序将存储在C:\\Users\\xxxx\\AppData\\Local\\Apps\\2.0

We could imagine a solution who will, for each user, list all the executable files in the tree, and only save the last versions. 我们可以想象一个解决方案,该解决方案将为每个用户列出树中的所有可执行文件,并仅保存最新版本。

Here is an example code snippet (single user) : 这是一个示例代码片段(单个用户):

var exes = Directory.EnumerateFiles(@"C:\Users\<user>\AppData\Local\Apps\2.0", "*.exe",
    SearchOption.AllDirectories);

var apps = new Dictionary<String, Tuple<String, Version>>();

foreach (var file in exes)
{
    var fileName = Path.GetFileName(file);

    Version v = null;
    Version.TryParse(FileVersionInfo.GetVersionInfo(file).FileVersion, out v);

    if (fileName == null || v == null) continue;

    if (!apps.ContainsKey(fileName))
    {
        apps.Add(fileName, new Tuple<string, Version>(file, v));    
    }
    else if (v > apps[fileName].Item2)
    {
        apps[fileName] = new Tuple<string, Version>(file, v);
    }
}

You'll find in the apps dictionary all the applications names as keys, and as values a Tuple containing the full path to the executable and it's version. 您会在apps字典中找到所有应用程序名称作为键,并以值的形式找到一个Tuple,其中包含可执行文件及其版本的完整路径。

Didn't find another way to get the information, but i hope it'll do the job 没有找到获取信息的另一种方法,但我希望它能胜任

Tried on my computer and it seems to work fine 在我的计算机上尝试过,似乎可以正常工作

If you know your application name, you can this way get the path to the last installed version. 如果知道您的应用程序名称,则可以通过这种方式获取上次安装版本的路径。

If not but you know where the .appref-ms is, you'll have to open it, get the application manifest (the .application file published by ClickOnce) and get the executable name from the assemblyIdentity node. 如果不是,但您知道.appref-ms在哪里,则必须将其打开,获取应用程序清单(由ClickOnce发布的.application文件),并从assemblyIdentity节点获取可执行文件名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM