C programming help needed.

shafiqdms1

Regular
Joined
May 3, 2008
Messages
124
WCA ID
2008MOHA01
YouTube
Visit Channel
I know a lot of you are programmers, so I thought of getting help here

In the computer lanuage C, what is the code used to detect OS (like Windows XP or Vista)?

I am trying to make a program that in the beginning it checks the operating system and says : "Windows XP detected" or "Windows Vista detected" when run on one of those operating systems, if you know the code, please share.


Thanks in advance,
-Shafiq
 
The system() function runs the given command by passing it to the default command interpreter. The return value is usually zero if the command executed without errors.

Now, the different OSes use different commands. You can test which commands work to see which OS is being used.
 
The system() function runs the given command by passing it to the default command interpreter. The return value is usually zero if the command executed without errors.

Now, the different OSes use different commands. You can test which commands work to see which OS is being used.

I tried integrating that into my program, but it doesnt work:

#include <stdio.h>
int main ( void ) {

system ()

printf( "%s", system);

getchar();

return 0;
}
 
Well, your OS is Windows. Do you want to determine your OS level? You may want to let us know which compiler you're using.

Also, why are you wanting to do this? You may be starting down the wrong path.
 
Well, your OS is Windows. Do you want to determine your OS level? You may want to let us know which compiler you're using.

Also, why are you wanting to do this? You may be starting down the wrong path.

yeah, that's what I mean, OS level. I am currently using Dev-C++ compiler. I wanted to make a simple program and integrate that into a later program that will do this:

1) Detect OS level
2) If Windows XP detected
2a) Do this
3) If Windows Vista detected
3a) Do this
4) End program
 
1) Detect OS level
2) If Windows XP detected
2a) Do this
3) If Windows Vista detected
3a) Do this
4) End program

Yes, but why do you want to do that? Would availability of a function be a better thing to determine what you're going to do?

I am making a science fair project that compares different computer speeds on different OS levels and I thought it would be nice to add a function that checks the OS level
 
Your program can't run on two OS simultaneously, so what's your check during runtime for? And why don't you use preprocessor directives. You have to compile it for each OS anyway, don't you?

I dont mean 2 OS's, I mean like, whats the word...OS level, like detecting Windows XP or Windows Vista
 
Your program can't run on two OS simultaneously

You could if you compiled it on windows, then ran it using boot camp or WINE or something, I'd think? Don't know what the point of that would be though.
That would require the Windows Vista Source Code. Which I'm pretty sure none of us have.

No it wouldn't. What Jim is asking is how would you know if you're running in a virtualized environment or not. The function you might have to determine OS could return some unknown value.
 
Back
Top