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?
Retrieve OS version
-
Marco
- Posts: 2354
- Joined: 27 Jun 2011 15:20
Retrieve OS version
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
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
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.
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
Maybe Don can expose the info with a variable like <osver>, formatted as digit.digit , who knows 
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]
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
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:
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
I'm convinced that Don can.Marco wrote:Maybe Don can expose the info with a variable like <osver>, formatted as digit.digit , who knows
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
A big thank for your effort, although I was looking for something really slim (see below)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]
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.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...
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]
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:
-
Marco
- Posts: 2354
- Joined: 27 Jun 2011 15:20
Re: Retrieve OS version
As of last beta, everything works smoothly using this new environment variable. Thanks!admin wrote:I will add a new env. variable %winver%.
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]
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
It "felt" more like an env.Marco wrote:As of last beta, everything works smoothly using this new environment variable. Thanks!admin wrote:I will add a new env. variable %winver%.
PS: may I ask why you choose the %% (i.e. env.) approach as opposed to <> ("normal")?
FAQ | XY News RSS | XY X
XYplorer Beta Club