Getting application version numbers in C#
-
Hello All. I would like to know what api calls/functions are required to retrieve all the application version numbers that are currently installed on a windows platform. What I want is to get all the version numbers as displayed when one goes to the Control Panel->Add/Remove Programs. I want to get the application names and the versions so I can generate reports, forward in an email etc. Does any body know how to do this? Many thanks, Matt
-
Hello All. I would like to know what api calls/functions are required to retrieve all the application version numbers that are currently installed on a windows platform. What I want is to get all the version numbers as displayed when one goes to the Control Panel->Add/Remove Programs. I want to get the application names and the versions so I can generate reports, forward in an email etc. Does any body know how to do this? Many thanks, Matt
You need to enumerate the registry entries in this location HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
Hello All. I would like to know what api calls/functions are required to retrieve all the application version numbers that are currently installed on a windows platform. What I want is to get all the version numbers as displayed when one goes to the Control Panel->Add/Remove Programs. I want to get the application names and the versions so I can generate reports, forward in an email etc. Does any body know how to do this? Many thanks, Matt
Try these: Assembly Version:
Assembly.GetExecutingAssembly().GetName().Version
File Version:
System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Try these: Assembly Version:
Assembly.GetExecutingAssembly().GetName().Version
File Version:
System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001He doesn't want o know his application's version but the version of all apllication on Windows... ;)
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Try these: Assembly Version:
Assembly.GetExecutingAssembly().GetName().Version
File Version:
System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thanks, but how do I use 'Assembly.GetExecutingAssembly().GetName().Version' to get the applications the at are 'installed' on the system?
-
Thanks, but how do I use 'Assembly.GetExecutingAssembly().GetName().Version' to get the applications the at are 'installed' on the system?
You'll have to use Interop services to check the version number of executables, and Use WMI to get a list of installed applications (look at the
Win32_Product
class). There is a "Version" property available that gives you what you want. BTW, there was no need for anyone to vote a 1 on my first response. That was pretty rude, considering nobody else has suggested a solution. Here's some code from one of my own projects. The GetObjectPropertyString() method is one of several helper methods I wrote that serve no other purpose than to clean up the code that I'm actually working in. No messy exception handling, no conversions - just a function call.//--------------------------------------------------------------------------------
private static string GetObjectPropertyString(ManagementObject mo, string name, string defaultValue)
{
string value = defaultValue;
try
{
value = mo[name].ToString();
}
catch (Exception ex)
{
if (ex != null) {}
#if DEBUG
System.Diagnostics.Trace.WriteLine(string.Format("GetObjectPropertyString() EXCEPTION - looking for {0} property", name));
#endif
}
return value;
}ManagementClass mc = new ManagementClass("Win32_Product");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
string name = GetObjectPropertyString(mo, "Name", ""); // you can also use "Caption" or "Description"
string version = GetObjectPropertyString(mo, "Version", "");
}"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001modified on Friday, September 5, 2008 11:28 AM
-
Try these: Assembly Version:
Assembly.GetExecutingAssembly().GetName().Version
File Version:
System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Also, I need to get the version of an installation, not the individual assemblies within it. For example, If I have a driver installer version 1.0. I may contain the following sets; driverX.sys version 1.1 driverY.sys version 1.11 driverZ.sys version 1.12 Where is the Add/Remove feature in the control panel looking to obtain the 1.0? Regards, Matt
-
Thanks, but how do I use 'Assembly.GetExecutingAssembly().GetName().Version' to get the applications the at are 'installed' on the system?
Did my last response help?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
You'll have to use Interop services to check the version number of executables, and Use WMI to get a list of installed applications (look at the
Win32_Product
class). There is a "Version" property available that gives you what you want. BTW, there was no need for anyone to vote a 1 on my first response. That was pretty rude, considering nobody else has suggested a solution. Here's some code from one of my own projects. The GetObjectPropertyString() method is one of several helper methods I wrote that serve no other purpose than to clean up the code that I'm actually working in. No messy exception handling, no conversions - just a function call.//--------------------------------------------------------------------------------
private static string GetObjectPropertyString(ManagementObject mo, string name, string defaultValue)
{
string value = defaultValue;
try
{
value = mo[name].ToString();
}
catch (Exception ex)
{
if (ex != null) {}
#if DEBUG
System.Diagnostics.Trace.WriteLine(string.Format("GetObjectPropertyString() EXCEPTION - looking for {0} property", name));
#endif
}
return value;
}ManagementClass mc = new ManagementClass("Win32_Product");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
string name = GetObjectPropertyString(mo, "Name", ""); // you can also use "Caption" or "Description"
string version = GetObjectPropertyString(mo, "Version", "");
}"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001modified on Friday, September 5, 2008 11:28 AM
Thanks very much for your email. It all work perfectly now. Many thanks. Matt
-
Did my last response help?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Hello John. thanks for your response concerning ManagementClass and ManagementObjectCollection. I have implemented this which returns everything that I need but it is hideously slow. I have had to run it in a seperate thread since it sometime takes minutes to finish. Is this normal? Is there another way you know which is faster? When one click add remove programs it does not take this long..... Thanks, Matt
-
Hello John. thanks for your response concerning ManagementClass and ManagementObjectCollection. I have implemented this which returns everything that I need but it is hideously slow. I have had to run it in a seperate thread since it sometime takes minutes to finish. Is this normal? Is there another way you know which is faster? When one click add remove programs it does not take this long..... Thanks, Matt
How long it takes depends on how much stuff you have installed, and what kind of system you have. I'm running XP-64 with 8gb of RAM and fairly speedy hard drives. With about 60 things installed, it takes about 4 seconds for Add/Remove Programs to populate itself. BTW, did you vote my response a 1?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
How long it takes depends on how much stuff you have installed, and what kind of system you have. I'm running XP-64 with 8gb of RAM and fairly speedy hard drives. With about 60 things installed, it takes about 4 seconds for Add/Remove Programs to populate itself. BTW, did you vote my response a 1?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001I am running a dual core 2.3g pentium 2 with 2 gb of ram. See below for a list for the output of the program - note the elapsed time; It is strange because when I go to contorl panel - add/remove programs it is allot faster - even for the first time after boot. Perhaps windows in caching the entries where as this method probably reads through the registry in a manual fashion....See the output of the program below. <<< Querying registry for installed components. Please wait... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................