Jump to content
  • Advertisement
Sign in to follow this  
Dom_152

Get Operating System at Run Time

This topic is 4370 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to get the Operating System the user is running an application on while the application is running? I know how to use defines to work out what platform it was built on and I can still use that method if need be. But it would be a lot more convinient if I could get it during run time.

Share this post


Link to post
Share on other sites
Advertisement
What language are you using? If you are using C/C++, I wouldn't really see the point because the executables are OS-specific anyway. Unless you want to check for version differences like Win98 vs WinXP.

Share this post


Link to post
Share on other sites
This is, ironically, OS-dependent. Windows has a function for returning the OS version, and (probably) so does OS X. In Linux, you might be able to determine the kernel version, perhaps even the distribution, but the OS is so flexible that there is no real notion of a "version" to be read.

Why, precisely, are you looking for this information?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you're talking about C++, I would just put platform dependent code within a try-except block.

Share this post


Link to post
Share on other sites
AP: but then, he'd need to find something that compiles, but reliably fails when executed, on a specific platform.

Share this post


Link to post
Share on other sites
If you want the version of a specific OS, use the OS's functionality for that.
If you want the type of OS (MacOS, Windows), you know it at compile time, so it is impossible to change it at run time.

Quote:

If you're talking about C++, I would just put platform dependent code within a try-except block.


That's not a solution. It just won't compile.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
If you're talking about C++, I would just put platform dependent code within a try-except block.


That doesn't make any sense, given that try-except is a Windows specific construct.

Anyway, given that you must decide between Windows/Linux at compile time (since you cannot possibly build a binary which runs on both), I assume your question is actually about operating system versions. For Windows, the function to call to get the operating system version is GetVersionEx.

Share this post


Link to post
Share on other sites
Oops that was one of my stupid moments. Thanks for the replies. Could anyone remind me of what the defines are for the different operating systems?
Ha I just noticed your user rating bakery2k1: User Rating: 1337 :P
Hey it tickled me :P

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
I know how to use defines to work out what platform it was built on and I can still use that method if need be.

http://predef.sourceforge.net/
i find it funny that within 30 mins you have forgot the defines!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!