Can QBASIC decect your OS
Can QBASIC decect your OS
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
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
By the way, I'm running Windows XP, and compile my programs with QuickBasic 4.5.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.....
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.
*****
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).
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).
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!
Xerol's Music - Updated Regularly!
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!
*****
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.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
Thanks everyone! Actually, what I ended up doing is just creating a MSDOS batch file thing.
I think it went something like this:
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?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!
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.
*****
Re: Can QBASIC decect your OS
In your initial post above you said you were running QB 4.5.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
Now you start talking about JustBasic and LibertyBasic.
What's going on?
*****
Try this:
I think this is a program I wrote a while ago, but I origanally wrote it in FUNCTION form.
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
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.
*****
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.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.