1

I am writing a application in which I need to create log for this I have to detect the OS that user using.Basically I am doing this from check OS version but the issue is both Windows Vista and Windows Server 2008 has the same version ie 6.0.So there is any other method to find the OS of user.

if (OSInfo.dwMajorVersion == 5 && OSInfo.dwMinorVersion == 1)
{
    s.AppendLine("OS Version              :" + " " + "Windows XP " + OSInfo.szCSDVersion + " " + "(Build Number : " + OSInfo.dwBuildNumber + ")");
}
else if (OSInfo.dwMajorVersion == 6 && OSInfo.dwMinorVersion == 0 && OSInfo.dwOSVersionInfoSize == 152 ) //&& OSInfo.wProductType != VER_NT_WORKSTATION)
{
    s.AppendLine("OS Version              :" + " " + "Windows VISTA/Windows Server 2008 " + OSInfo.szCSDVersion + " " + "(Build Number : " + OSInfo.dwBuildNumber + ")");
}
else if (OSInfo.dwMajorVersion == 6 && OSInfo.dwMinorVersion == 1)
{
    s.AppendLine("OS Version              :" + " " + "Windows7 " + OSInfo.szCSDVersion + " " + "(Build Number :" + OSInfo.dwBuildNumber + ")");
}
else if (OSInfo.dwMajorVersion == 5 && OSInfo.dwMinorVersion == 2)
{
    s.AppendLine("OS Version              :" + " " + "Windows Server 2003 " + OSInfo.szCSDVersion + " " + "(Build Number :" + OSInfo.dwBuildNumber + ")");
}
tshepang
  • 12,111
  • 21
  • 91
  • 136
abhi294074
  • 257
  • 1
  • 3
  • 9
  • 2
    Please don't do it that way. Also, read: http://blogs.msdn.com/b/oldnewthing/archive/2004/02/13/72476.aspx - if you are using this for log purposes, why does it have to be pretty? Isn't it enough to dump out the contents of `OSVERSIONEX` in text form? – 0xC0000022L Feb 09 '12 at 14:14
  • 2
    Any reason you can't use `Environment.OSVersion`? – Oded Feb 09 '12 at 14:17

1 Answers1

1

Perhaps You could read this stackoverflow post Detect Windows version in .net or this article could help you http://andrewensley.com/2009/06/c-detect-windows-os-part-1/

Best regards

Community
  • 1
  • 1
maxiperez
  • 1,470
  • 2
  • 20
  • 40