What's Here?
- Members: 244,179
- Replies: 692,924
- Topics: 113,123
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,345
- Members: 91
- Guests: 1,254
|
Gets a list of installed software and, if known, the software's install path.
|
Submitted By: aj32
|
|
Rating:
  
|
|
Views: 8,444 |
Language: C#
|
|
Last Modified: May 31, 2008 |
Instructions: 1. Add 'Using Microsoft.Win32' at the top of your code.
2. Put the following code into a class.
3. See example on using the code. |
Snippet
/// <summary>
/// Gets a list of installed software and, if known, the software's install path.
/// </summary>
/// <returns></returns>
private string Getinstalledsoftware()
{
//Declare the string to hold the list:
string Software = null;
//The registry key:
string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
{
//Let's go through the registry keys and get the info we need:
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
//If the key has value, continue, if not, skip it:
if (!(sk.GetValue("DisplayName") == null))
{
//Is the install location known?
if (sk.GetValue("InstallLocation") == null)
Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
else
Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
}
}
catch (Exception ex)
{
//No, that exception is not getting away... :P
}
}
}
}
return Software;
}
//EXAMPLE USAGE:
private void get_software_list_button__Click(object sender, EventArgs e)
{
MessageBox.Show(Getinstalledsoftware());
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|