Retrieve OS version

Discuss and share scripts and script files...
Post Reply
Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Retrieve OS version

Post by Marco »

I'd like to write a script that behaves differently based on which OS is running on.
My idea would be writing an if loop, but I've no way to know the OS version.
I thought of getting the version number of a core file like explorer.exe , but doesn't seem "elegant".

Any ideas?
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Retrieve OS version

Post by highend »

Don't know of any elegant way to find out the operating system (e.g. through build in tools in XYplorer).

A non elegant would be:

run a hidden dos box command with "ver >%temp%\osversion.txt" and parse that file for the relevant information.
One of my scripts helped you out? Please donate via Paypal

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Retrieve OS version

Post by Marco »

Maybe Don can expose the info with a variable like <osver>, formatted as digit.digit , who knows :roll:
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Retrieve OS version

Post by Stefan »

If you want you can execute an VBScript which writes to an file,
then use XYplorer to read this file and get the info you want:

Code: Select all

'//   Visual Basic Script VBS

Dim WSH : Set WSH = Wscript.CreateObject("WScript.Shell")
TEMPUser = WSH.ExpandEnvironmentStrings("%tmp%")

'2600 - 7601 ?
Build = WSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentBuildNumber")

'Microsoft Windows XP - Windows 7 ?
OS = WSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")

'Service Pack 3 -  Service Pack 1 ?
SP = WSH.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion")

'32-bit - 64-bit ?
'//On 64-bit %ProgramW6432% is present and set to %ProgramFiles%
OSbit = WSH.ExpandEnvironmentStrings("%ProgramW6432%")
'//On 32-bit %ProgramW6432% is not present and so i get %ProgramW6432% back 
If (LCase(OSbit) = "%programw6432%") Then OSbit = "32" ELSE OSbit = "64"

'-------------------------------
Out =  "Build " & Build & " is " & OS & ", here with " & SP & " and " & OSbit & "-bit"
'-------------------------------
'MsgBox Out
'-------------------------------
'Write Out to an file:
Dim FSO : Set FSO  = Wscript.CreateObject("Scripting.FileSystemObject")
Const ForWriting = 2
Const CreateIfNotExist = True
Set fsOut = FSO.OpenTextFile(TEMPUser & "\_myOS.txt", ForWriting, CreateIfNotExist)
    fsOut.WriteLine Out
    fsout.close
'-------------------------------
'WSH.run TEMPUser & "\_myOS.txt"
'-------------------------------
'With XYplorer use something like:
'::$a = readfile("%tmp%\_myOS.txt"); msg $a;
'and some code to get the needed info.


PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Retrieve OS version

Post by PeterH »

Marco wrote:Maybe Don can expose the info with a variable like <osver>, formatted as digit.digit , who knows :roll:
I'm convinced that Don can.
And I am surprised that Windows doesn't show this in an environment variable, but only by the ver-command. (Else you could use that variable directly in XY.)

XY already shows Windows Information on Help / Various Information. When filling a variable I think he should copy *all* information into it - either as shown by ver, or as shown in XY Various Information. Else after some time someone will ask for the "missing" information...

By the way: isn't there any possibility to directly retrieve the output of a command executed from XY (by Goto '!!command')? This could be quite helpful.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Retrieve OS version

Post by Marco »

Stefan wrote:If you want you can execute an VBScript which writes to an file,
then use XYplorer to read this file and get the info you want:[cut]
A big thank for your effort, although I was looking for something really slim (see below)
PeterH wrote:I'm convinced that Don can.
And I am surprised that Windows doesn't show this in an environment variable, but only by the ver-command. (Else you could use that variable directly in XY.)

XY already shows Windows Information on Help / Various Information. When filling a variable I think he should copy *all* information into it - either as shown by ver, or as shown in XY Various Information. Else after some time someone will ask for the "missing" information...
Exactly, I read every environment variable available and I am baffled by the fact that seems impossible to retrieve the OS version, or at least the kernel version.
Basically I was looking for something that returns 5.1 for XP, 6.0 for Vista and 6.1 for 7 (i.e. the very last piece of info that XY provides in Various Information, more of a major kernel version I should have written in the topic title). This would allow compact and simple code, like

Code: Select all

if (<osver> < "6.0") {
 ...code for XP...
}
else {
 ...code for Vista and/or 7...
}
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 66249
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Retrieve OS version

Post by admin »

I will add a new env. variable %winver%.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Retrieve OS version

Post by Marco »

admin wrote:I will add a new env. variable %winver%.
As of last beta, everything works smoothly using this new environment variable. Thanks!
PS: may I ask why you choose the %% (i.e. env.) approach as opposed to <> ("normal")?
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 66249
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Retrieve OS version

Post by admin »

Marco wrote:
admin wrote:I will add a new env. variable %winver%.
As of last beta, everything works smoothly using this new environment variable. Thanks!
PS: may I ask why you choose the %% (i.e. env.) approach as opposed to <> ("normal")?
It "felt" more like an env. :)

Post Reply