我需要找到在命令提示符下运行它的路径将打开应用程序。
对于一个实例 - 我在我的系统上安装了Picasa 3,使用下面的代码我可以访问已安装的文件夹位置。
private string FindByDisplayName(RegistryKey parentKey, string name)
{
string[] nameList = parentKey.GetSubKeyNames();
for (int i = 0; i < nameList.Length; i++)
{
RegistryKey regKey = parentKey.OpenSubKey(nameList[i]);
try
{
if (regKey.GetValue("DisplayName").ToString() == name)
{
return regKey.GetValue("InstallLocation").ToString();
}
}
catch { }
}
return "";
}
private void button1_Click(object sender, EventArgs e)
{
String AppName = textBox1.Text.ToString();
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
string location = FindByDisplayName(regKey, AppName);
MessageBox.Show(location);
}
此代码的输出将给我 -
C:\ Program Files(x86)\ Google \ Picasa 3
但我想要准确的.exe文件,它会打开Picasa 3桌面应用程序,因为上面的输出位置包含多个可执行文件,例如:一个用于打开应用程序,另一个用于卸载它。
希望我的问题清楚。