Page 1 of 1
Retrieve OS version
Posted: 27 Nov 2011 22:19
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?
Re: Retrieve OS version
Posted: 27 Nov 2011 22:38
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.
Re: Retrieve OS version
Posted: 28 Nov 2011 09:16
by Marco
Maybe Don can expose the info with a variable like <osver>, formatted as digit.digit , who knows

Re: Retrieve OS version
Posted: 28 Nov 2011 11:54
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.
Re: Retrieve OS version
Posted: 28 Nov 2011 12:16
by PeterH
Marco wrote:Maybe Don can expose the info with a variable like <osver>, formatted as digit.digit , who knows

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.
Re: Retrieve OS version
Posted: 28 Nov 2011 15:29
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...
}
Re: Retrieve OS version
Posted: 28 Nov 2011 15:39
by admin
I will add a new env. variable %winver%.
Re: Retrieve OS version
Posted: 29 Nov 2011 10:21
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")?
Re: Retrieve OS version
Posted: 29 Nov 2011 11:12
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.
