globi84
(Just in Town)
2015-10-26 10:01 AM
Compare Operating System Version

Hi Kixtart Community

in our company do we use for a logon script kixtart.

I want make for the Windows 8 and later Users some changes different then the Windows 7 Users.

My Idea was like this.

 Code:
$osversion = @DOS
if $osversion >= 6.2
	? "Do something for Windows 8 and later."
else
	? "Do Something for Windows 7 and earlier."
endif


this compare doesn't work every time is this compare true.

When I set the variable "$osversion" for example
 Code:
$osversion = 5.2


I think the problem is something wrong with the data type that I get from the "@DOS" command.

Can you give me a tip to fix this problem.

regards

christian


BradV
(Seasoned Scripter)
2015-10-26 11:27 AM
Re: Compare Operating System Version

Kixtart is not strongly typed. Try adding in some error checking:

 Code:
if @DOS >= 6.2
   ? @SERROR
   ? "Do Windows 8 stuff"
else
   ? @SERROR
   ? "Do Windows 7 stuff"
endif

See what that gives you.


Arend_
(MM club member)
2015-10-26 11:52 AM
Re: Compare Operating System Version

Try using this:
 Code:
$osversion = ReadValue("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","CurrentVersion")


Glenn BarnasAdministrator
(KiX Supporter)
2015-10-26 11:53 AM
Re: Compare Operating System Version

You can force a numeric compare with $Ver = Val(@DOS), or $Ver = 1.0 * @DOS.

In the second form, Kix sees a decimal number and converts the entire process to that format based on the first item referenced. Multiplying by 1.0 doesn't change the value but forces Kix to use precision math.

@DOS might return a version string, which will throw things off.

Glenn


Glenn BarnasAdministrator
(KiX Supporter)
2015-10-26 12:03 PM
Re: Compare Operating System Version

Taking a minute to run "VarTypeName(@DOS)" confirms that it does return a string. This is the reason for inconsistent results. In my Universal Login Script, I have a global var that holds the OS Version as a number, available to other functions that might need it.

Glenn


globi84
(Just in Town)
2015-10-26 12:04 PM
Re: Compare Operating System Version

Thanks glenn

with the function val() works now.

thank you for your fast response.

regards

christian


globi84
(Just in Town)
2015-10-26 02:55 PM
Re: Compare Operating System Version

Sorry with val it doesn't work too.

with the "1.0 *" I get just the first digit. i think this is a problem about the "," char. in Switzerland we have comma separated not with a point.

@arend

With your solution i have the same problem with "@DOS"

now I make the check with @PRODUCTTYPE

 Code:
if @PRODUCTTYPE == "Windows 7 Enterprise Edition"
	;? "Do Something for Windows 7"
else
	;? "Do something for other Windows"
endif


in this way I don' t have the flexibility with a numeric variable. but on this way I can make different between the Windows 7 and the others.

thanks for your help

regards

christian


AllenAdministrator
(KiX Supporter)
2015-10-26 03:15 PM
Re: Compare Operating System Version

Please post your code for the 1.0* code, there is probably something amiss.

As for the other code, this will likely cover your bases a bit better.

 Code:
Select 
  Case instr(@producttype,"Windows 7")
    ;do stuff
  Case instr(@producttype,"Windows 8")
    ;do stuff
  Case 1
    ? "OS not covered"
Endselect


Glenn BarnasAdministrator
(KiX Supporter)
2015-10-26 06:22 PM
Re: Compare Operating System Version

Did you try 1,0 * @DOS? You need to be consistent with the regional settings.

The multiplication by 1 doesn't change the value, and specifying a decimal point forces the value to be a real number, not an integer.

Glenn


Arend_
(MM club member)
2015-10-27 09:26 AM
Re: Compare Operating System Version

Personally I use code similar to Allen's:
 Code:
Select 
  Case Left(@ProductType,9) = "Windows 7"
    ;do stuff
  Case Left(@ProductType,9) = "Windows 8"
    ;do stuff
  Case Left(@ProductType,10) = "Windows 10"
    ;do stuff
  Case 1
    ? "OS not covered"
Endselect


AlexTheGreat
(Just in Town)
2019-04-16 08:48 PM
Re: Compare Operating System Version

The following table summarizes the most recent operating system version numbers.

Operating system Version number
Windows 10= 10.0*
Windows Server 2019= 10.0*
Windows Server 2016= 10.0*
Windows 8.1= 6.3*
Windows Server 2012 R2= 6.3*
Windows 8= 6.2
Windows Server 2012= 6.2
Windows 7= 6.1
Windows Server 2008 R2= 6.1
Windows Server 2008= 6.0
Windows Vista= 6.0
Windows Server 2003 R2= 5.2
Windows Server 2003= 5.2
Windows XP 64-Bit Ed= 5.2
Windows XP= 5.1
Windows 2000= 5.0

Source:
https://docs.microsoft.com/en-us/windows/desktop/SysInfo/operating-system-version


LonkeroAdministrator
(KiX Master Guru)
2019-04-17 03:29 PM
Re: Compare Operating System Version

Thank you Alex.

Just so everyone knows, @dos indeed returns 10.0 on windows 10 but after some updates it can also return 6.1

this seems to have to do with windows 10 not guarding the value in:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

where kix seems to get it. I have only seen this issue once and I believe it was after a .net installation/patch.