Thread: winver, winminor, winmajor can it be found from dos?

  1. #1
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350

    winver, winminor, winmajor can it be found from dos?

    I'm working on a dos only program (16 bit real mode), yet I want to check for a windows host OS. I wish to abort my program with a "dos OS only" sort of error message if windooze is detected. I know I can find the dos underlay of win9x using osmajor and osminor, but what about win versions that emulate dos such as NT, 2000, and XP?

    My compiler has winver, winminor, and winmajor, but not in the dos libraries. Outside of doing something like checking for ntldr files or winnt directories is there a way from dos to check if newer versions of windows is running?

    TIA
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  2. #2
    Registered User Unimatrix139's Avatar
    Join Date
    Jun 2002
    Posts
    55

    Windoze

    I've figured out ways to detect if windoze exists on the root of HDD C, but not if it is active

    Code:
    #include <string.h>
    #include <io.h>
    #include <direct.h>
    #include <dos.h>
    
    FILE *fp;
    char *starstring, sizedstring1[700], sizedstring2[700];
    int i;
    char ver[40];
    
    main()
    {
       system("cd >c:\iswin.tmp");
       system("C:");
       chdir("\\");
       dos_setfileattr("msdos.sys", FA_NORMAL);
       fp=fopen("msdos.sys", "r");
       if(fp==NULL)
       {
          printf("Unable to open C:\\MSDOS.SYS\n");
          return(0);
       }
       starstring=fgets(sizedstring1, 700, fp);
       starstring=fgets(sizedstring1, 8, fp);
       if(strncmp(starstring, "WinDir=", 7)==0)
       {
          printf("Windows is installed.\n");
          starstring=fgets(sizedstring1, 700, fp);
          printf("Windows primary directory is %s", starstring);
          fclose(fp);
          system("VER >>~tmp01.tmo");
          fp=fopen("~tmp01.tmo", "r");
          starstring=fgets(ver, 7, fp);
          starstring=fgets(ver, 20, fp);
          fclose(fp);
          remove("~tmp01.tmo");
          if((strncmp(starstring, "Window", 6)==0))
          {
             if(strncmp(starstring, "Windows 95", 10)==0)
             {
                printf("Major version 'Windows 95'\n");
             }
             if(strncmp(starstring, "Windows 98", 10)==0)
             {
                printf("Major version 'Windows 98'\n");
             }
             if(strncmp(starstring, "Windows Mi", 10)==0)
             {
                printf("Major version 'Windows Millenium'\n");
             }
          }
          if(strncmp(starstring, "Microsoft Windows XP", 20)==0)
          {   
             printf("Major version 'Windows XP'\n");
          }
          i=1;
       }
       else
       {
          printf("Windows is not installed.\n");
          fclose(fp);
          i=0;
       }
       dos_setfileattr("msdos.sys", FA_HIDDEN);
       fp=fopen("iswin.tmp", "r");
       starstring=fgets(sizedstring1, 700, fp);
       fclose(fp);
       strcpy(sizedstring2, "cd ");
       strcat(sizedstring2, sizedstring1);
       system(sizedstring2);
       strcpy(sizedstring2, "/0");
       strncpy(sizedstring2, starstring, 2);
       system(sizedstring2);
       remove("C:\iswin.tmp");
       return(i); /* if return errorlevel is 1 then windows was detected. */
    }
    it reads from MSDOS.SYS. I also did it with system("ver >>tmp.tmp"); and read from tmp.tmp.
    Kree'ta Tau'ri! Chaapa'ai!

  3. #3
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Hey, this looks interesting. Thanks for the reply
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can I issue a command to DOS from within a program?
    By Sukarn in forum Windows Programming
    Replies: 2
    Last Post: 12-22-2006, 07:44 AM
  2. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  3. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. real mode dos & win dos
    By scott27349 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-19-2002, 06:15 AM