PDA

View Full Version : winver, winminor, winmajor can it be found from dos?



ronin
09-26-2002, 08:18 PM
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

Unimatrix139
09-29-2002, 08:32 AM
I've figured out ways to detect if windoze exists on the root of HDD C, but not if it is active :(



#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.

ronin
10-02-2002, 10:32 AM
Hey, this looks interesting. Thanks for the reply :)