0

Possible Duplicate:
How do I determine if a computer is running XP Service pack 3

There's a ton of C++ code illustrating how to check that OS is Windows XP, but I need to know if it's at least Windows XP SP3. Is there any way to do that?

Community
  • 1
  • 1
ahmd0
  • 16,633
  • 33
  • 137
  • 233
  • 1
    Duplicate? Yes, but for the Love of God, don't use the registry as some answers suggest. – Christian.K Dec 15 '12 at 18:51
  • Again, as I posted below `szCSDVersion` provides a string version of the Service Pack, which would be OK for display purposes, but there's no clear indication on how to determine if it's actually SP3. – ahmd0 Dec 15 '12 at 19:02
  • Actually, this is not a duplicate of that post. I've now read it in detail and that post specifically asks for registry or file system. But here you are asking for a programmatic way. – David Heffernan Dec 15 '12 at 19:07
  • Yes, I'm curious, if anyone even reads questions before posting "exact duplicate"? This has become a real issue for this forum... – ahmd0 Dec 15 '12 at 19:10
  • 2
    So, the way you do it is call `GetVersionEx` passing `OSVERSIONINFOEX`. You then look at `dwMajorVersion` and `dwMinorVersion`. If it's > 5.1 you are good. It it's < 5.1 you are not good. If it's `== 5.1` then you are on XP and have to check the SP. Look at `wServicePackMajor` and compare with 3. – David Heffernan Dec 15 '12 at 19:12
  • I've very sorry that I was one of your close voters. I voted to reopen. I did not read closely enough the question that was asked. I just assumed it was programmatic. Does my comment above help? – David Heffernan Dec 15 '12 at 19:13
  • 1
    When testing for SP3 you also need to think about server 2003. That is version 5.2. But early versions of server 2003 pre-date XP SP3. This is one of the reasons why you should test if functionality is available rather than doing version checks. – David Heffernan Dec 15 '12 at 19:15
  • @DavidHeffernan: Thanks for your input. You have a point here. I'm now wondering, if there's an API that was added in XP SP3. That way it would be another way to check for it by doing GetProcAddress on it? As for checking for functionality, I need to know this before the app is installed. – ahmd0 Dec 15 '12 at 19:20
  • @DavidHeffernan: What do you think, if I do: `HMODULE hMod = ::LoadLibrary(L"Wlanapi.dll");` and then `BOOL bAtLeastWinXP_SP3 = ::GetProcAddress(hMod, "WlanCloseHandle") != NULL;`? – ahmd0 Dec 15 '12 at 19:28
  • 1
    I'd test for the specific functionality that you need. What is it that is driving the need for SP3 rather than SP2? Test for whatever that is. – David Heffernan Dec 15 '12 at 19:30

1 Answers1

2

This page should help:

Getting the System Version (Windows)

ArtemStorozhuk
  • 8,715
  • 4
  • 35
  • 53
  • I'm sorry, but this is not really helpful. I obviously got to that page from a Google search first, but it contains no reference to Windows XP SP3. Or did I miss something? All it has is `szCSDVersion` parameter, which is a string! Am I supposed to parse it somehow? – ahmd0 Dec 15 '12 at 18:56
  • This function returns the OS and the service pack! You just have to check the output string. – marscode Dec 15 '12 at 19:10
  • 1
    It is the proper way to do this. The `OSVERSIONINFOEX` structure has the service pack information in it. That example isn't the best at pointing it out, but take a look at the `wServicePackMajor` and `wServicePackMinor` fields. – Retired Ninja Dec 15 '12 at 19:11
  • 1
    Well, the string will be exactly "Service Pack 3", but then you are right that a strin comparison is not the most robust way. Check the members of the OSVVERSIONINFO [structure](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx). For XP SP3, the major version is 5, the minor version is 1 and the build is 2600. – Christian.K Dec 15 '12 at 19:12
  • 1
    @Christian.K No, don't check build. Major.Minor == 5.1 identifies XP. – David Heffernan Dec 15 '12 at 19:14
  • Yes, but doesn't the specific build number identify the sp? albeit indirectly, so your suggestion is better of course. – Christian.K Dec 15 '12 at 19:16
  • No that is wrong. All SPs of XP have build 2600. – David Heffernan Dec 15 '12 at 19:32