问题
i am using this to get the program names, but i need the exe names. How do i find them?
string SoftwareKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products";
RegistryKey rk = default(RegistryKey);
rk = Registry.LocalMachine.OpenSubKey(SoftwareKey);
//string skname = null;
string sname = string.Empty;
foreach (string skname in rk.GetSubKeyNames())
{
try
{
sname = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("DisplayName").ToString();
listBox1.Items.Add(sname);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I am trying to do this:
System.Diagnostics.Process.Start("Name.exe");
to run the program.
回答1:
The installer doesn't, and really couldn't, know about the actuall executables. It only knows about the installation package - the .MSI file.
In order to get the names of the executables (yes, many "programs" are composed of numerous .EXE files) you would need to interrogate the .MSI file.
回答2:
In Windows, programs are normally installed by msi file and there can be multiple exe installed by a single package. It's true that sometimes programs are installed by setup.exe but they are just a wrapper extracting the real msi file.
Some vendor like InstallShield might store the setup.exe somewhere in the local harddrive just in case user needs to launch the setup.exe again for modify\uninstallation purpose. However, this is vendor specific implementation.
回答3:
Lacking a clarification on the particulars, you can get the .exe's on local drives as such:
var allExePaths =
from drive in Environment.GetLogicalDrives()
from exePath in Directory.GetFiles(drive, "*.exe", SearchOption.AllDirectories)
select exePath;
If you're looking for a particular one, please provide more details about what things will determine the one you're looking for. Using the registry to list installed programs doesn't seem to be what you want to do, so please be more specific.
来源:https://stackoverflow.com/questions/11322653/getting-exe-name-of-installed-programs-in-c