Page 1 of 1 1
Topic Options
#210856 - 2015-10-26 10:01 AM Compare Operating System Version
globi84 Offline
Just in Town

Registered: 2015-10-26
Posts: 3
Loc: Switzerland
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


Edited by globi84 (2015-10-26 10:01 AM)

Top
#210857 - 2015-10-26 11:27 AM Re: Compare Operating System Version [Re: globi84]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 679
Loc: Maryland, USA
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.

Top
#210858 - 2015-10-26 11:52 AM Re: Compare Operating System Version [Re: globi84]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1870
Loc: Hilversum, The Netherlands
Try using this:
 Code:
$osversion = ReadValue("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","CurrentVersion")

Top
#210859 - 2015-10-26 11:53 AM Re: Compare Operating System Version [Re: BradV]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4303
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210860 - 2015-10-26 12:03 PM Re: Compare Operating System Version [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4303
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210861 - 2015-10-26 12:04 PM Re: Compare Operating System Version [Re: Glenn Barnas]
globi84 Offline
Just in Town

Registered: 2015-10-26
Posts: 3
Loc: Switzerland
Thanks glenn

with the function val() works now.

thank you for your fast response.

regards

christian

Top
#210862 - 2015-10-26 02:55 PM Re: Compare Operating System Version [Re: globi84]
globi84 Offline
Just in Town

Registered: 2015-10-26
Posts: 3
Loc: Switzerland
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

Top
#210863 - 2015-10-26 03:15 PM Re: Compare Operating System Version [Re: globi84]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4480
Loc: USA
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

Top
#210864 - 2015-10-26 06:22 PM Re: Compare Operating System Version [Re: globi84]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4303
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210867 - 2015-10-27 09:26 AM Re: Compare Operating System Version [Re: Allen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1870
Loc: Hilversum, The Netherlands
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

Top
#213671 - 2019-04-16 08:48 PM Re: Compare Operating System Version [Re: Arend_]
AlexTheGreat Offline
Just in Town

Registered: 2017-12-13
Posts: 1
Loc: CA
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

Top
#213672 - 2019-04-17 03:29 PM Re: Compare Operating System Version [Re: AlexTheGreat]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 204 anonymous users online.
Newest Members
Stefan_H, khalidkhan786, BigDGeorge, jefff, QCarvalho
17672 Registered Users

Generated in 0.037 seconds in which 0.012 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org