|
-
November 16th, 2010, 11:45 PM
#1
How to determine OS using C language ?
Hello Everyone,
My requirement is such that, I need to identify OS (in my case it is Windows 7) in C language and based on that condition have to proceed further.
As we have 2 OS(Windows 7 and Windows Server 2008 R2) having the similar dwMajorVersion(6) and dwMinorVersion(1) but different product type.
So we can differentiate "Windows 7" and "Windows Server 2008 R2" by product type.
But my problem begins here:
Currently I am working on "Microsoft Windows XP".
On Windows XP Structure OSVERSIONINFOEX->
Code:
typedef struct _OSVERSIONINFOEXA {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wReserved[2];
}
It does not contain variable to get information about product type that is "wProductType".
Request you to please help me, how to determine the OS type between "Windows 7" and "Windows Server 2008 R2" considering I am coding on Microsft Windows XP.
Thanks.
-
November 17th, 2010, 07:43 AM
#2
Re: How to determine OS using C language ?
Struct OSVERSIONINFOEX is defined (beginning with the Windows 2000) as
Code:
typedef struct _OSVERSIONINFOEX {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wSuiteMask;
BYTE wProductType;
BYTE wReserved;
} OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;
At least it is what my very old MSDN from October 2000 says...
Victor Nijegorodov
-
November 17th, 2010, 03:50 PM
#3
Re: How to determine OS using C language ?
-
November 18th, 2010, 08:56 PM
#4
Re: How to determine OS using C language ?
Hello Everyone,
Thank you all for your quick responses.
But I don't know the reason behind the structure OSVERSIONINFOEX that is showing on Microsoft Windows XP professional version 2002 as below.
It does not have following 2 variables:
Code:
WORD wSuiteMask;
BYTE wProductType;
On Microsoft Windows XP Structure OSVERSIONINFOEX->
Code:
typedef struct _OSVERSIONINFOEXA {
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
WORD wServicePackMajor;
WORD wServicePackMinor;
WORD wReserved[2];
}OSVERSIONINFOEXA, *POSVERSIONINFOEX,A *LPOSVERSIONINFOEXA;
Thanks.
-
November 20th, 2010, 05:49 AM
#5
Re: How to determine OS using C language ?
What compiler do you use?
-
November 20th, 2010, 10:23 AM
#6
Re: How to determine OS using C language ?
Hi,
I am using Visual Studio.
Thanks.
-
November 20th, 2010, 05:19 PM
#7
Re: How to determine OS using C language ?
 Originally Posted by anish2006
Hi,
I am using Visual Studio.
Which one: 6.0, 2003, 2005, 2008, 2010, or maybe 4.2?
Victor Nijegorodov
-
November 21st, 2010, 08:33 PM
#8
Re: How to determine OS using C language ?
It is Microsoft Visual C++ 6.0
Thanks.
-
November 22nd, 2010, 01:16 AM
#9
Re: How to determine OS using C language ?
Please find below code which I am trying to compile on Microsoft Visual C++ 6.0, however compilation is unsuccessful due to Line 13,
Code:
include <stdio.h>
#include <windows.h>
#pragma comment(lib, "User32.lib")
#define BUFSIZE 256
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
Line 1: int main()
Line 2: {
Line 3: OSVERSIONINFOEX osvi;
Line 4:
Line 5: ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
Line 6: osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
Line 7: GetVersionEx((OSVERSIONINFO *)&osvi);
Line 8:
Line 9: if ( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
Line 10: {
Line 11: if(osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1)
Line 12: {
Line 13: if(osvi.wProductType == VER_NT_WORKSTATION)
Line 14: {
Line 15: // do something
Line 16: }
Line 17: }
Line 18: }
Line 19: }
Giving following compilation error->
Code:
C:\Test\CheckOS.c(51): error C2039: 'wProductType' : '_OSVERSIONINFOEXA' is not a memeber.
C:\program files\microsoft visual studio\vc98\include\winbase.h(7998) : OSVERSIONINFOEXA' Please check the declaration.
Thanks.
-
November 22nd, 2010, 02:08 AM
#10
Re: How to determine OS using C language ?
I guess you need to download and install the Platform SDK for VC++6.0 (the last version is from Feb. 2000) to correctly compile it
Victor Nijegorodov
-
November 22nd, 2010, 03:48 AM
#11
Re: How to determine OS using C language ?
Thanks VictorN,
I will download and install the Platform SDK for VC++6.0 and try again and will let you know, once it works.
Thanks a lot.
-
November 22nd, 2010, 04:08 PM
#12
Re: How to determine OS using C language ?
You could also consider getting yourself a modern compiler. Even with that SDK the headers will not contain the new stuff added during the last 10 years.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|