Author:
- Scott Gasch (scott@wannabe.guru.org) 22 Aug 2002
+ Scott Gasch (scott@gasch.org) 22 Aug 2002
Revision History:
--*/
-#include <stdlib.h>
+#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
// stdout about which version of the windows operating system is running
// and sets the errorlevel to one of the values below accordingly. Might
// be useful in your CMD/BAT script...
-//
+//
#define EXIT_WIN95 (1)
#define EXIT_WIN98 (2)
#define EXIT_WINME (3)
#define EXIT_VISTA (13)
#define EXIT_UNKNOWN (14)
-CHAR *g_szWindowsNames[] =
+CHAR *g_szWindowsNames[] =
{
"Not Used",
"Windows95",
typedef BOOL (*FUNCTION_PTR)(OSVERSIONINFO *);
-BOOL
+BOOL
TryWinNT(DWORD *pdwMajor, DWORD *pdwMinor, DWORD *pdwPlatform)
/*++
BOOL fRet = FALSE;
HMODULE h = NULL;
OSVERSIONINFOEXA osvi;
-
+
h = LoadLibraryA("kernel32.dll");
if (NULL == h)
{
- fprintf(stderr, "Failed to load kernel32.dll, error=%u.\n",
+ fprintf(stderr, "Failed to load kernel32.dll, error=%u.\n",
GetLastError());
goto end;
}
-
+
p = (FUNCTION_PTR)GetProcAddress(h, "GetVersionExA");
if (NULL == p)
{
{
FreeLibrary(h);
}
-
+
return(fRet);
}
-int __cdecl
+int __cdecl
main(void)
/*++
//
// This call should be available on all versions of Windows
- //
+ //
dwVersion = GetVersion();
if ((dwVersion & 0x80000000) ||
(FALSE == TryWinNT(&dwMajor, &dwMinor, &dwPlatform)))
//
// Parse results
- //
+ //
if (dwPlatform == VER_PLATFORM_WIN32_NT)
{
switch(dwMajor)
iRet = EXIT_NT351;
}
goto end;
-
+
case 4:
iRet = EXIT_NT4OTHER;
if (0 == dwMinor)
iRet = EXIT_NT4;
}
goto end;
-
+
case 5:
iRet = EXIT_NT5OTHER;
if (0 == dwMinor)
iRet = EXIT_WIN_SERVER_2003;
}
goto end;
-
+
case 6:
iRet = EXIT_VISTA;
goto end;
-
+
default:
goto end;
}
iRet = EXIT_WINME;
}
goto end;
-
+
default:
goto end;
}
}
-
+
end:
printf("%s %u.%u -- errorlevel is %d\n",
g_szWindowsNames[iRet],