Page 1 of 1

Can QBASIC decect your OS

Posted: Thu Dec 01, 2005 6:01 pm
by Andrew
Hey, I have no experience with QUICK BASIC, but I do have a lot of experience (well, i dont if "a lot" is a good way to say it) with another BASIC (justbasic.com).

I am running QB 4.5, the old msdos one. What I want it to do it is write what OS you have to a text file.

Any code or ideas would be great!!!
THANKS!
-Andrew

Re: Can QBASIC decect your OS

Posted: Thu Dec 01, 2005 7:12 pm
by Guest
Andrew wrote:.....
I am running QB 4.5, the old msdos one. What I want it to do it is write what OS you have to a text file.....
By the way, I'm running Windows XP, and compile my programs with QuickBasic 4.5.
My first idea was a little program which did:
SHELL "VER >WHICHOS.TXT

However, this generates text that says:
MS-DOS Version 5.xxxxx

If I type VER on the MSDOS command-line, I get:
Microsoft Windows XP [Version 5.xxxxx]
This is what you want.
So, the SHELL is no good.

Then I tried a little batch file with the following command:
VER >WHICHOS.TXT
Running from the MSDOS command-line, it works.
However, I tried executing the batch file from a program using the SHELL, and got the wrong answer again.

Hmmm, I'm fresh out of ideas. Maybe someone else can help.
*****

Posted: Thu Dec 01, 2005 7:14 pm
by moneo
Above post was by me (Moneo).
Still having log in problems.
*****

Posted: Thu Dec 01, 2005 7:23 pm
by DrV
In Windows NT-based OSes (like XP) the default command interpreter is cmd.exe, which is a regular 32-bit Windows console application, whereas 16-bit DOS apps get a classic 16-bit DOS COMMAND.COM whenever they try to execute anything, as in QB's SHELL.

As for your question, I don't know of any easy way to get that information in a DOS program; however, if you don't mind writing a Windows program in some other language like C or FreeBASIC, you could easily find the information you want with GetVersion() or GetVersionEx() (see MSDN for more information).

Posted: Thu Dec 01, 2005 9:10 pm
by Xerol
Couldn't you check to see if certain files are in certain places? A bit of a workaround, but it could work.

Posted: Thu Dec 01, 2005 9:22 pm
by moneo
Andrew,

I got this logic from Ethan Winer's book, chapter 6, at:
www.ethanwiner.com
It stuffs the VER command into the keyboard buffer so that when the program ends what's in the buffer gets executed. Windows, therefore, thinks that the command was keyed in by the user on the MSDOS command-line. I shortened the name of the text file to WHOS because only 15 characters can be put into the buffer.

PS, I tried it and it works.
Good luck!
*****

Code: Select all

DEFINT A-Z
Work$="VER >WHOS"+chr$(13)
Length = LEN(Work$)

'----- Set the segment for poking, define the buffer head and tail, and
'      then poke each character.
DEF SEG = 0
POKE 1050, 30
POKE 1052, 30 + Length * 2
FOR X = 1 TO Length
    POKE 1052 + X * 2, ASC(MID$(Work$, X))
NEXT X
SYSTEM

Posted: Sat Dec 03, 2005 3:04 pm
by moneo
So, Andrew, did my solution work for you?
*****

Posted: Sat Dec 03, 2005 10:18 pm
by Andrew
Thanks everyone! Actually, what I ended up doing is just creating a MSDOS batch file thing.

I think it went something like this:

Code: Select all

open "test.bat" for output as #a
print #a, "Ver > version.txt"
print #a, "echo Close this"
close #a

[/open]
Then it can just read the file. Please note, I dont know if the above code will work with QBASIC, but it will with either Just BASIC or Liberty BASIC.

Thanks! 

Posted: Sat Dec 03, 2005 11:14 pm
by Antoni
Microsoft used to recomend to use ENVIRON$:
-If the variable windir exists, you are in a shell in some version of windows (from 3.0 to XP)
-If the variable OS exists you are in windows NT-2000-XP

Not so accurate as SHELL "VER>file"...

Posted: Sun Dec 04, 2005 2:53 pm
by moneo
Andrew wrote:Thanks everyone! Actually, what I ended up doing is just creating a MSDOS batch file thing.

I think it went something like this:

Code: Select all

open "test.bat" for output as #a
print #a, "Ver > version.txt"
print #a, "echo Close this"
close #a

[/open]
Then it can just read the file. Please note, I dont know if the above code will work with QBASIC, but it will with either Just BASIC or Liberty BASIC.

Thanks! 
The question is: from where do you execute the "test.bat" batch file?

If you are executing it from the MSDOS command-line, then it works.

However, as I stated in a previous post, if you try to execute the batch file from your program via a SHELL, it won't work. If this is the case, then you need to use the POKE logic that I posted before.
*****

Posted: Sun Dec 04, 2005 5:18 pm
by Andrew
I dont think that's the exact code of it, I am just writting it off memory. And that is for use with Just BASIC or Liberty BASIC, not QBASIC. Thanks

Re: Can QBASIC decect your OS

Posted: Sun Dec 04, 2005 8:44 pm
by moneo
Andrew wrote:Hey, I have no experience with QUICK BASIC, but I do have a lot of experience (well, i dont if "a lot" is a good way to say it) with another BASIC (justbasic.com).

I am running QB 4.5, the old msdos one. What I want it to do it is write what OS you have to a text file.

Any code or ideas would be great!!!
THANKS!
-Andrew
In your initial post above you said you were running QB 4.5.
Now you start talking about JustBasic and LibertyBasic.
What's going on?
*****

Posted: Mon Dec 05, 2005 1:15 pm
by PQBC with a guess
Try this:

Code: Select all

'Windows checker -PQBC
CLS
Shell "ver"
For x = 1 to 80
Let character$ = CHR$(SCREEN(1,x))
Let winver$ = winver$ + character$
next x
open "c:\output.txt for output as #1
print #1, winver$
close #1
I think this is a program I wrote a while ago, but I origanally wrote it in FUNCTION form.

Posted: Mon Dec 05, 2005 2:18 pm
by moneo
PQBC,

Your solution may work with earlier versions of Windows. But, with Windows XP it won't work, as I posted above on Dec 01, 6:12 pm.

The "VER" from a SHELL will give you the MSDOS version, and not the Windows version that you want. Doing a "VER" from the MSDOS command-line will show the Windows version.

The code that I posted above on Dec 01, 8:22 pm will execute a "VER" as if it was entered on the MSDOS command-line, by stuffing the command into the keyboard buffer when the QB program terminates.
*****