Get list of installed softwares on machines in your network

I was looking for a way to get list of softwares installed in machines in our network for verifying something. I did not wanted to go & login in each machine & then collection list of software from add / remove programs.  

So I decided to write a small program that will do this for me.

This is how we can do it. List that you see in add remove program is stored in Machine registry at path SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall  under local machine.

So your program will connect to registry of each machine specified & read the list. Then compile that list by removing list items such as Updates / Fixes etc as per requirement.

Below function will enumerate the software installed in a text file & also will display it on console application.

private static void WriteSoftwareListToFile(string MachineName , string ReportFileName)

{

StreamWriter sw;

if (File.Exists(ReportFileName))

{

sw = File.AppendText(ReportFileName);

}

else

{

sw = File.CreateText(ReportFileName);

}

sw.WriteLine(“\r\nSoftwares installed on “ + MachineName +

” on “ + DateTime.Now.ToShortDateString() + ” “ + DateTime.Now.ToLongTimeString());

//Registry path which has information of all the softwares installed on machine

string uninstallKey = @”SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”;

// using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))

sw.WriteLine(“\r\nSoftware Name \t Software Version”);

try

{

using (RegistryKey rk =

RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, MachineName).

OpenSubKey(uninstallKey))

{

foreach (string skName in rk.GetSubKeyNames())

{

using (RegistryKey sk = rk.OpenSubKey(skName))

{

string SoftwareName = string.Empty;

string SoftwareVersion = string.Empty;

try

{

SoftwareName = sk.GetValue(“DisplayName”).ToString();

SoftwareVersion = sk.GetValue(“DisplayVersion”).ToString();

}

catch (NullReferenceException exNull)

{

SoftwareName = string.Empty;

SoftwareVersion = string.Empty;

}

if (SoftwareName != string.Empty)

{

//Exclude Updates , Fixes

if (!(SoftwareName.Contains(“Security Update for Windows”) ||

SoftwareName.Contains(“Hotfix for”) ||

SoftwareName.Contains(“Update for”) ||

SoftwareName.Contains(“Update for Windows”)))

{

Console.WriteLine(SoftwareName + ” “ + SoftwareVersion);

sw.WriteLine(SoftwareName + “\t” + SoftwareVersion);

}

}

}

}

}

}

catch (Exception Ex)

{

sw.WriteLine(“\r\n Exception :” + Ex.Message);

}

sw.Close();

}

 

You can call this functions for all require machines in your network like below. Please note if you are running the application your domain ID need to have registry read access for all the machines your are accessing.

 

static void Main(string[] args)

{

string[] Machines = new string[]

{

“MachineHostName1”,

“MachineHostName2”,

“MachineHostName3”,

“MachineHostName4”,

“MachineHostName5”,

“MachineHostName6” };

string FILE_NAME = “SoftwareList_” + DateTime.Now.ToShortDateString().Replace(“/”, “”) + “.log”;

for (int i = 0; i < Machines.Length; i++ )

WriteSoftwareListToFile(Machines[i], FILE_NAME);

Console.ReadLine(); // To make the o/p readable.

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *