如何以编程方式获取另一个应用程序的安装路径? [英] How can I get another application's installation path programmatically?

查看:23
本文介绍了如何以编程方式获取另一个应用程序的安装路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道应用程序的安装路径在哪里.我知道它通常在 ...Program Files ... 中,但我猜有些人将它安装在不同的位置.我知道应用程序的名称.

I'd like to know where the installation path for an application is. I know it usually is in ...Program Files... but I guess some people install it in different locations. I do know the name of the application.

谢谢.

推荐答案

(在 Windows 上)查找程序安装路径的理想方法是从注册表中读取它.大多数安装程序会为该程序创建一个包含安装路径的注册表项.此密钥的确切位置以及它将命名的内容因相关程序而异.

The ideal way to find a program's installation path (on Windows) is to read it from the registry. Most installers will create a registry key for that program that contains the installation path. Exactly where this key is and what it will be named varies depending on the program in question.

要查找程序在注册表中是否有密钥,请打开regedit"并使用编辑 > 查找选项尝试使用程序名称查找密钥.如果存在这样的密钥,您可以使用 RegistryKey .NET Framework 库中的类.

To find if the program has a key in the registry, open 'regedit' and use the Edit > Find option to try and locate a key with the program name. If such a key exists, you can read it using the RegistryKey class in the .NET Framework library.

如果程序没有注册表项,那么另一个选择就是要求用户使用 OpenFileDialog 定位 .exe 文件,尽管这显然不理想.

If the program does not have a registry key then another option is just to ask the user to locate the .exe file with the OpenFileDialog, although this is obviously not ideal.

这篇关于如何以编程方式获取另一个应用程序的安装路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆