Can QBASIC decect your OS

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Andrew

Can QBASIC decect your OS

Post by Andrew » Thu Dec 01, 2005 6:01 pm

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

Guest

Re: Can QBASIC decect your OS

Post by Guest » Thu Dec 01, 2005 7:12 pm

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

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Thu Dec 01, 2005 7:14 pm

Above post was by me (Moneo).
Still having log in problems.
*****

DrV
Veteran
Posts: 63
Joined: Thu Jun 02, 2005 9:44 pm

Post by DrV » Thu Dec 01, 2005 7:23 pm

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

User avatar
Xerol
Veteran
Posts: 81
Joined: Tue Jan 04, 2005 6:27 pm
Location: Timonium, MD
Contact:

Post by Xerol » Thu Dec 01, 2005 9:10 pm

Couldn't you check to see if certain files are in certain places? A bit of a workaround, but it could work.
If you need music composed in MP3, WAV, or MIDI format, please contact me via email.

Xerol's Music - Updated Regularly!

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Thu Dec 01, 2005 9:22 pm

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
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Sat Dec 03, 2005 3:04 pm

So, Andrew, did my solution work for you?
*****

Andrew

Post by Andrew » Sat Dec 03, 2005 10:18 pm

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! 

Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni » Sat Dec 03, 2005 11:14 pm

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

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Sun Dec 04, 2005 2:53 pm

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

Andrew

Post by Andrew » Sun Dec 04, 2005 5:18 pm

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

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: Can QBASIC decect your OS

Post by moneo » Sun Dec 04, 2005 8:44 pm

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?
*****

PQBC with a guess

Post by PQBC with a guess » Mon Dec 05, 2005 1:15 pm

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.

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Mon Dec 05, 2005 2:18 pm

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.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.

Post Reply