Thread: How to get OS parameters

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    3

    How to get OS parameters

    I am wanting to write a debug tool to give out to customers that, ultimately, could run off most OS and would report the user's OS specifics in the log file. Windows/mac, maybe unix...

    How do I obtain the OS parameters (ie platform, version number etc)?

    Any help/advice appreciated.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can't do that by standard functions, so you would have to define your own function that is implemented differently depending on the OS (you may find that the same source code works on both Linux, Solaris and BSD/MacOS, but certainly NOT on Windows).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    This would involve macros. You would use the preprocessor with code like
    Code:
    #ifdef <macro>
    It's expected that the _WIN32 macro is defined for 32-bit Windows. I don't know what it would define for 64-bit. I have no idea what macros identify a Mac, and you'd have to look into what macros are defined for the various Unices.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    3
    Thanks for the comments. I am still fairly new to C++... assuming, for now, we just aim for windows. what is the the best way to get the system parameters? I've had suggestions for getenv() or GetSystemInfo()... is one better than the other? I havent found alot of documentation/info regarding either function's usage...

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    There was a project years ago to write a program that could run on different processors and OS's, at teh time, both DOS and MAC-OS. The conclusion we came to was that while it is technically feasable to do, it was certainly non-trivial. With newer OS's that do a signature check it may no longer be possible, since a windows executable has a lot of header info that woudl make it an invalid MAC or LINUX program. I recall the original intent was to create a system neutral boot sector for linux. It basically comes down to using the differential execution of teh two or more instruction sets to split the execution stream into multiple paths, then each path being specific to a particular processor can execute more specialized boot code.
    Last edited by abachler; 11-26-2008 at 10:44 AM.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by smboucou View Post
    Thanks for the comments. I am still fairly new to C++... assuming, for now, we just aim for windows. what is the the best way to get the system parameters? I've had suggestions for getenv() or GetSystemInfo()... is one better than the other? I havent found alot of documentation/info regarding either function's usage...
    Google for "msdn GetSystemInfo" - it is a pretty good tool for getting SOME system information.

    I posted something on the subject of getting more info a few days ago. If I can find it, I'll post a link.

    Abachler, I think you are talking on a single executable that runs on multiple platforms. That is quite tricky - it can be done, but it's quite hard to get right. For larger projects, it's likely best to have a small "boot-strap" executable that starts another executable once the correct OS has been determined. But generally, that's the job of an installer, and not part of the application itself. [And the more different architectures this is for, the harder it gets].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Check if something like this already exists (which it probably does). Maybe in Boost or some other library?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting if OS is Windows???
    By Ktulu in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2006, 02:49 AM
  2. function with variable number of parameters
    By mikahell in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 03:35 PM
  3. a simple OS
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-06-2004, 10:47 PM
  4. Linux OS to Windows OS code
    By sw9830 in forum C Programming
    Replies: 2
    Last Post: 02-28-2003, 03:11 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM