QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: krovit on October 30, 2020, 05:16:27 am

Title: System Info of windows
Post by: krovit on October 30, 2020, 05:16:27 am
I am in trouble to determine the version of windows in use.

ENVIRON$ behaves differently depending on the version of windows and use GetVersion() is Microsoft depreciated...
batch files?

Can you give me some info?

Thanks!
Title: Re: System Info of windows
Post by: FellippeHeitor on October 30, 2020, 05:46:51 am
Sounds like a job for @SpriggsySpriggs!
Title: Re: System Info of windows
Post by: SMcNeill on October 30, 2020, 09:19:09 am
Shell out to: systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

All you'll need to do is pipe the info there to clipboard, or to a file, and then read it in.  (change quotes to CHR$(34) characters for the SHELL statement to avoid issues.)

Results look like this (for Win 10):

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"      <-- the command
OS Name:                   Microsoft Windows 10 Pro   <-- it's output
OS Version:                10.0.18363 N/A Build 18363  <-- on two lines... other OS versions may have more lines of information for you.



You can also just stick to the simple old VER command...

Code: [Select]
SHELL "ver>temp.txt"
OPEN "temp.txt" FOR INPUT AS #1
LINE INPUT #1, blank$ 'output is a blank line
LINE INPUT #1, ver$ 'and then the version, for some odd reason
PRINT ver$
CLOSE
KILL "temp.txt"
Title: Re: System Info of windows
Post by: krovit on October 30, 2020, 04:41:33 pm
Thank you SMcNeill

I actually hoped that there would be a system to get that information without using the dear batch files, that is, without writing anything, but that's fine too. your example is complete and comprehensive.

Title: Re: System Info of windows
Post by: SpriggsySpriggs on October 30, 2020, 07:03:43 pm
I actually hoped that there would be a system to get that information without using the dear batch files, that is, without writing anything, but that's fine too
@krovit
Here is some code that doesn't require writing to a file. This is generally faster than most regular SHELLs as well. Download the attached "pipecom.h" file and put it with your code.

Code: QB64: [Select]
  1.  
  2. DECLARE LIBRARY ".\pipecom"
  3.     FUNCTION pipecom$ (cmd AS STRING)
  4.  
  5. ver = MID$(pipecom("ver"), 2)
  6. PRINT ver
Title: Re: System Info of windows
Post by: FellippeHeitor on October 30, 2020, 07:13:49 pm
Important reminder: once compiled, the .h file doesn't have to be shipped with your exe, if that's a concern.
Title: Re: System Info of windows
Post by: krovit on October 31, 2020, 05:15:11 am
Hey! Thank you! now I can choose the method between the BAT file and your routine

I only have one question... I'm almost ashamed...
The *.h file seems to me to be a script in C or Java or similar languages. I saw that he goes to look for it in the same folder as the . Bas.
You tell me to import it into my code, but actually don't like that.

The fact is that no experience with the .h and QB64 files: I need a little teaching to figure out how to do in these cases...

Title: Re: System Info of windows
Post by: TempodiBasic on October 31, 2020, 07:14:42 am
Hi Krovit
in my little experience the .h files is like a DLL but GCC++ accepts it as sourceCcode at the place of a compiled file DLL.
All you need at compiling time is that the .h file must be in the QB64.exe folder and a declaration of it into the code like an external library as it does the code of Spriggsy.
At runtime you needn't the .h file, so you can think it more like a .BM file than a DLL because it has been included into the .EXE  got by compilation.

PS: have you joined to Discord for QB64?
I have tried it and I find it cool!
Title: Re: System Info of windows
Post by: krovit on October 31, 2020, 07:35:22 am
Grazie TempoDiBasic

Thank you now it's very clear the help that these little routines can give to qb64.

"Discord"...? I don't know what it is!
Title: Re: System Info of windows
Post by: bplus on October 31, 2020, 11:10:44 am
Quote
"Discord"...? I don't know what it is!

QB64 chat room on Internet, see our Home Page Announcements (at bottom) 2nd Board or just link https://discord.com/invite/2t9HTYK
Title: Re: System Info of windows
Post by: SpriggsySpriggs on November 01, 2020, 05:46:04 pm
@krovit I have some new code posted here that makes the Windows version operate better. No more console window popping up.

https://www.qb64.org/forum/index.php?topic=3168.msg124345#msg124345 (https://www.qb64.org/forum/index.php?topic=3168.msg124345#msg124345)
Title: Re: System Info of windows
Post by: bplus on November 01, 2020, 06:11:30 pm
Have you checked Wiki:
https://www.qb64.org/wiki/ENVIRON$
Title: Re: System Info of windows
Post by: FellippeHeitor on November 01, 2020, 06:15:30 pm
Have you checked Wiki:
https://www.qb64.org/wiki/ENVIRON$

He says so in the first post.
Title: Re: System Info of windows
Post by: bplus on November 01, 2020, 06:25:01 pm
Man if it's not in here?
Code: QB64: [Select]
  1.   i = i + 1
  2.   setting$ = ENVIRON$(i) ' get a setting from the list
  3.   PRINT setting$
  4.   IF i MOD 20 = 0 THEN PRINT "Press a key": SLEEP: CLS
  5. LOOP UNTIL setting$ = ""
  6.  
Title: Re: System Info of windows
Post by: luke on November 02, 2020, 12:53:58 am
Quick question, what do you need the windows version for?
Title: Re: System Info of windows
Post by: krovit on November 02, 2020, 02:38:48 pm
Quick question, what do you need the windows version for?

Application behavior sometimes changes when run on windows7 or windows10.
The OS are similar but certainly not the same and every now and then you find some surprises so it is useful to predict these critical issues.

Title: Re: System Info of windows
Post by: krovit on November 02, 2020, 02:42:47 pm
Man if it's not in here?
Code: QB64: [Select]
  1.   i = i + 1
  2.   setting$ = ENVIRON$(i) ' get a setting from the list
  3.   PRINT setting$
  4.   IF i MOD 20 = 0 THEN PRINT "Press a key": SLEEP: CLS
  5. LOOP UNTIL setting$ = ""
  6.  

The behavior of ENVIRON$() is different in the two systems (win10 and win7) and the result seems unreliable.
At least that's what I've checked several times on multiple machines.

QB64 probably lacks a function that simply returns (in any OS) the OS, version and even the user's name and his folder.

Title: Re: System Info of windows
Post by: krovit on November 02, 2020, 02:45:01 pm
@krovit I have some new code posted here that makes the Windows version operate better. No more console window popping up.

https://www.qb64.org/forum/index.php?topic=3168.msg124345#msg124345 (https://www.qb64.org/forum/index.php?topic=3168.msg124345#msg124345)

Thank you! I consider it immediately for my applications...
Title: Re: System Info of windows
Post by: bplus on November 02, 2020, 03:45:06 pm
Well this works for 10, how 'bout 7?
Code: QB64: [Select]
  1. SHELL "ver > ver.txt"
  2. OPEN "ver.txt" FOR BINARY AS #1
  3. ver$ = SPACE$(LOF(1))
  4. GET #1, , ver$
  5. PRINT ver$
  6. PRINT MID$(ver$, INSTR(LCASE$(ver$), "version") + LEN("version "), 2) 'modify as needed
  7.  

@krovit  Same as Steve, no batch file is involved. So wth? are you just being difficult? ;-))

PS I never knew my widows version was so many characters long! ;-)
Title: Re: System Info of windows
Post by: SpriggsySpriggs on November 02, 2020, 04:19:26 pm
@bplus He also mentioned he was hoping to not have to write to a file at all.
Title: Re: System Info of windows
Post by: krovit on November 02, 2020, 04:21:46 pm
Well this works for 10, how 'bout 7?
Code: QB64: [Select]
  1. SHELL "ver > ver.txt"
  2. OPEN "ver.txt" FOR BINARY AS #1
  3. ver$ = SPACE$(LOF(1))
  4. GET #1, , ver$
  5. PRINT ver$
  6. PRINT MID$(ver$, INSTR(LCASE$(ver$), "version") + LEN("version "), 2) 'modify as needed
  7.  

@krovit  Same as Steve, no batch file is involved. So wth? are you just being difficult? ;-))

PS I never knew my widows version was so many characters long! ;-)

I'm afraid I don't understand (OT: ah! foreign languages... i'm not able to talk it... I only speak Italian, and I would hope well... it is a beautiful language, with 250 thousand words! and we use 2000 and no; inside is especially Latin and Ancient Greek, and then German, Spanish, French... lastly also English (imported as it is, but then it's not really "Italian language") and one thing we can say in a thousand ways and a thousand nuances).

The code for the batch file is fine just and it works in the two OS but forces to access the disk and if you can avoid it seems better.

Title: Re: System Info of windows
Post by: bplus on November 02, 2020, 05:05:56 pm
Code: QB64: [Select]
  1. save$ = _CLIPBOARD$
  2. SHELL "ver | clip" ' << I AM NOT A FREAKIN BAT FILE!  ;-))
  3. _CLIPBOARD$ = save$
  4. PRINT ver$
  5.  
Title: Re: System Info of windows
Post by: krovit on November 03, 2020, 02:53:53 am
Code: QB64: [Select]
  1. save$ = _CLIPBOARD$
  2. SHELL "ver | clip" ' << I AM NOT A FREAKIN BAT FILE!  ;-))
  3. _CLIPBOARD$ = save$
  4. PRINT ver$
  5.  

Thank you BPlus this latest version is very, very nice and works (I have to test it on win7 to catch the differences with win10).
The previous truths, however, made use of a file (SHELL "ver > ver.txt" / OPEN "ver.txt" FOR BINARY AS #1 etc..)

Anyway... i can't understand the trick, which is how it can work...


Title: Re: System Info of windows
Post by: krovit on November 03, 2020, 03:30:49 am
https://jrsoftware.org/ishelp/index.php?topic=winvernotes (https://jrsoftware.org/ishelp/index.php?topic=winvernotes)

6.0.6000   Windows Vista
6.0.6001   Windows Vista with Service Pack 1 'or Windows Server 2008
6.1.7600   Windows 7 'or Windows Server 2008 R2
6.1.7601   Windows 7 with Service Pack 1 'or Windows Server 2008 R2 with Service Pack 1
6.2.9200   Windows 8 'or Windows Server 2012
6.3.9200   Windows 8.1 'or Windows Server 2012 R2
6.3.9600   Windows 8.1 with Update 1
10.0.10240   Windows 10 Version 1507
10.0.10586   Windows 10 Version 1511 (November Update)
10.0.14393   Windows 10 Version 1607 (Anniversary Update) 'or Windows Server 2016
10.0.15063   Windows 10 Version 1703 (Creators Update)
10.0.16299   Windows 10 Version 1709 (Fall Creators Update)
10.0.17134   Windows 10 Version 1803 (April 2018 Update)
10.0.17763   Windows 10 Version 1809 (October 2018 Update) 'or Windows Server 2019
10.0.18362   Windows 10 Version 1903 (May 2019 Update)
10.0.18363   Windows 10 Version 1909 (November 2019 Update)
10.0.19041   Windows 10 Version 2004 (May 2020 Update)
Note that there is normally no need to specify the build numbers (i.e., you may simply use "6.2" for Windows 8)

Title: Re: System Info of windows
Post by: SpriggsySpriggs on November 03, 2020, 08:44:52 am
Thank you BPlus this latest version is very, very nice and works (I have to test it on win7 to catch the differences with win10).
The previous truths, however, made use of a file (SHELL "ver > ver.txt" / OPEN "ver.txt" FOR BINARY AS #1 etc..)

Anyway... i can't understand the trick, which is how it can work...
@krovit Just remember that by piping to clip it slows down the command sometimes to being 1/3 the speed of a regular SHELL or pipecom.
Title: Re: System Info of windows
Post by: krovit on November 03, 2020, 09:00:52 am
@krovit Just remember that by piping to clip it slows down the command sometimes to being 1/3 the speed of a regular SHELL or pipecom.

Ahhgh!!!

We say (in Italy, in your areas i don't know...): "give me a hot and a cold one", or even "a crush and a raw one"... to indicate that every time there is something that contradicts the previous time...
Title: Re: System Info of windows
Post by: bplus on November 03, 2020, 09:56:57 am
Ahhgh!!!

We say (in Italy, in your areas i don't know...): "give me a hot and a cold one", or even "a crush and a raw one"... to indicate that every time there is something that contradicts the previous time...

Instead of sighing I would demand proof ;-)) specially if clipboard is cleared before piping. :O

Besides what's 1/3 or .001, you only do it once, sip some coffee ;-))
Title: Re: System Info of windows
Post by: krovit on November 03, 2020, 10:35:49 am
Instead of sighing I would demand proof ;-)) specially if clipboard is cleared before piping. :O

Besides what's 1/3 or .001, you only do it once, sip some coffee ;-))

I actually did a lot of rehearsals and I can't notice the difference, in terms of the time spent.
But I am a perfectionist (that's why I can't finish my projects... a classic!) and I know that if I leave something there, settle for something there, pretend I don't see it that way... eventually the difference you'll see.

Optimizing your code is critical for any project...


Title: Re: System Info of windows
Post by: bplus on November 03, 2020, 11:10:18 am
I actually did a lot of rehearsals and I can't notice the difference, in terms of the time spent.
But I am a perfectionist (that's why I can't finish my projects... a classic!) and I know that if I leave something there, settle for something there, pretend I don't see it that way... eventually the difference you'll see.

Optimizing your code is critical for any project...


My philosophy is:

FIRST get it working, then get it working right THEN get it optimized.

Because we all know it's never going to be perfect unless it's math ;-))
Quote
(that's why I can't finish my projects... a classic!)

Really no sense in optimizing excrement ;-))
Title: Re: System Info of windows
Post by: SpriggsySpriggs on November 03, 2020, 04:22:11 pm
@krovit I have updated the code for pipecom here:
https://www.qb64.org/forum/index.php?topic=3168.0 (https://www.qb64.org/forum/index.php?topic=3168.0)

There was a bug that caused data duplication.
Title: Re: System Info of windows
Post by: krovit on November 04, 2020, 12:37:34 pm
@krovit I have updated the code for pipecom here:
https://www.qb64.org/forum/index.php?topic=3168.0 (https://www.qb64.org/forum/index.php?topic=3168.0)

There was a bug that caused data duplication.

Ok, thank you!