How to Determine OS

I want a win32 console program to determine if its running in WIN9x or WINNT.
theberAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
Use

OSVERSIONINFO osviVerInfo;
osviVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO);

GetVersionEx ( &osviVerInfo);

switch ( osviVerInfo.dwPlatformId)
{
 case VER_PLATFORM_WIN32_WINDOWS: // Win32 on Win95
      break;
 case VER_PLATFORM_WIN32_NT: // Win32 on WinNT
      break;
 case VER_PLATFORM_WIN32_WIN32sS: // Win32s on Win 3.x
      break;
}
0
 
theberAuthor Commented:
Edited text of question.
0
 
theberAuthor Commented:
Edited text of question.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jkrCommented:
Or (a little bit more convenient ;-)

BOOL    IsNT    ()
{
    OSVERSIONINFO       osviVerInfo;

    osviVerInfo.dwOSVersionInfoSize =   sizeof  (   OSVERSIONINFO);

    GetVersionEx    (   &osviVerInfo);

    return  (   VER_PLATFORM_WIN32_NT   ==  osviVerInfo.dwPlatformId);
    return  (   TRUE);
}
0
 
jkrCommented:
Ooops, sorry, this should of course be

BOOL    IsNT    ()
{
    OSVERSIONINFO       osviVerInfo;

    osviVerInfo.dwOSVersionInfoSize =   sizeof  (   OSVERSIONINFO);

    GetVersionEx    (   &osviVerInfo);

    return  (   VER_PLATFORM_WIN32_NT   ==  osviVerInfo.dwPlatformId);
 }
0
 
jkrCommented:
If you want this to be a complete program, use

#include <windows.h>
#include <stdio.h>

BOOL    IsNT    ()
{
    OSVERSIONINFO       osviVerInfo;

    osviVerInfo.dwOSVersionInfoSize =   sizeof  (   OSVERSIONINFO);

    GetVersionEx    (   &osviVerInfo);

    return  (   VER_PLATFORM_WIN32_NT   ==  osviVerInfo.dwPlatformId);
}

void main ( void)
{
 if ( IsNT())
     printf ( "\nThis is Windows NT\n");
 else
     printf ( "\nThis is Windows 9x\n");
}
0
All Courses

From novice to tech pro — start learning today.