Detecting service packs

M

Mark Rae

Hi,

I'm looking for a reliable way of detecting the version of Windows that the
..NET framework is installed on, specifically the service pack. Currently,
I'm using System.Environment.OSVersion and pulling the Major, Minor, Build
and Revision properties out of that.

However, e.g. Windows XP returns exactly the same values for no initial
build, SP1 or SP2.

I found the following site:
http://www.c-sharpcorner.com/FAQ/OSVersionUsingEnvClass.asp which makes
reference to a .CSD property of System.Environment.OSVersion, but I don't
think that's correct.

Is a call to the WinAPI GetVersionEx function the only way to achieve this?

Mark
 
S

Shiva

How about using WMI?

-- Code Start --
ObjectQuery oQuery = new System.Management.ObjectQuery("SELECT CSDVersion
FROM Win32_OperatingSystem");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oQuery);
ManagementObjectCollection result = oSearcher.Get();
foreach (ManagementObject mo in result) Console.WriteLine
(mo["CSDVersion"].ToString());
-- Code End --

HTH

Hi,

I'm looking for a reliable way of detecting the version of Windows that the
..NET framework is installed on, specifically the service pack. Currently,
I'm using System.Environment.OSVersion and pulling the Major, Minor, Build
and Revision properties out of that.

However, e.g. Windows XP returns exactly the same values for no initial
build, SP1 or SP2.

I found the following site:
http://www.c-sharpcorner.com/FAQ/OSVersionUsingEnvClass.asp which makes
reference to a .CSD property of System.Environment.OSVersion, but I don't
think that's correct.

Is a call to the WinAPI GetVersionEx function the only way to achieve this?

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top