Detecting service packs

  • Thread starter Thread starter Mark Rae
  • Start date Start date
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
 
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
 
Back
Top