Thread: OS Information ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    OS Information ...

    Hey dudes ...

    This is my first post so go easy on me OK -

    How would I go about getting information on the current OS that my application is running. My application is designed to run under a windows enviroment and I would like it to under any version of windows ... 9*, 200, me, nt etc etc ...

    My application is console based and very simple, but I would love to gain this information ... The app in NO way uses Win32 code ... its a pure MS-DOS application ...

    Oh and another thing, how do I run applications from C and could I run the built in FTP program thats comes with Windows without it being shown in the console ?

    What I mean is, say I wonna connect to a FTP Server for an update without the user seeing it ... but just tell the user thats its being done ?

    Thanks in advance for any replys ...

  2. #2
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    Someone smarter than me is going to have to answer your first question!
    My application is console based and very simple, but I would love to gain this information ... The app in NO way uses Win32 code ... its a pure MS-DOS application ...
    I am assuming that you mean you are writing a windows console type application, which means that it is in actual fact not an MS-DOS application but a console app.
    Oh and another thing, how do I run applications from C and could I run the built in FTP program thats comes with Windows without it being shown in the console ?
    You may want to look at the system command:
    int system( const char *command );
    But your probably not going to be in luck with the FTP thing. It is an interactive program, so while you could call it from your c program, I can't think of any way that you could actually interact with it.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    If you are writing a console app, i.e. a 32 bit app, then you can use the GetVersionEx() API function to get the version, it is not ideal, but the info is there.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    If you are getting the information to determine which compatible code to use for each system, try this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #ifdef _POSIX_ 
      #define PRINTF "POSIX"
    #elif _WIN32 
      #define PRINT "Windows"
    #elif _LINUX_
      #define PRINT "Linux"
    #elif _MAC
      #define PRINT "Mac"
    #endif
    
    int main ( void )
    {
      puts ( PRINT );
      return EXIT_SUCCESS;
    }
    I'm not sure if the last two #elif's use the correct variable, but the first two do. If you simply want information on the environment of your system, this should work nicely if your compiler supports the char **env argument to main.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /* Nonstandard arguments to main.
    ** This program may not work on 
    ** all systems.
    */
    int main ( int argc, char **argv, char **env )
    {
      int i;
      for ( i = 0; env[i] != NULL; i++ )
        (void)puts ( env[i] );
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. Programming an OS
    By minesweeper in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-09-2002, 06:51 PM
  3. 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
  4. What do YOU want in a OS?
    By commanderrulz in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 09-30-2001, 06:25 AM
  5. Find OS in C
    By Snuffy2 in forum C Programming
    Replies: 10
    Last Post: 09-09-2001, 04:40 PM