So work is slow and i am an intern and am generally installing lots of programs on computer that have been reformatted or possibly are missing software. I Recently came across a pre-built code which search the registry for already installed programs only one problem is that i cannot get it to work. here is what i have. I really want to expand it over time and use a GUI and such along with customizing it. Allowing me to see what is missing and a form/gui where i can link buttons to installers. The error i am getting is
"Error 1 The name 'Installed' does not exist in the current context" I am right that i am some how missing a function to call Installed. I am new to C# and havent had a lot of in depth experience with it.
Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click (object sender, EventArgs e)
{
MessageBox.Show(Installed());
}
}
}
Class1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace WindowsFormsApplication2
{
class Class1
{
/// <summary>
/// Gets a list of installed software and, if known, the software's install path.
/// </summary>
/// <returns></returns>
private string Installed()
{
//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;
}
}
}