Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OS() always return Windows 6.02 4

Status
Not open for further replies.

Nro

Programmer
May 15, 2001
337
CA
I’ve read different posts and the use of OS() function seem very straightforward… but if I use it on Windows 10, Windows 8.2 or Windows 11, I always have the same result : Windows 6.02
I’m using VFP 9.
Thanks in advance
 
This is correct. I don't know why you are seeing those particular figures, but they are the documented values. You might try calling OS(5) to get the build number, which should allow you to distinguish between the various versions. There is also an API function you could call, but off-hand I don't remember what it is. No doubt someone else here will enlighten us.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Me said:
There is also an API function you could call, but off-hand I don't remember what it is.

If I had bothered to switch on my brain before posting that, I would have realised the function is called GetVersion(). No parameters. It returns the major and minor Windows version numbers.

Full documentation here:
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks, Mike, for your help. I have the same result on Win 10, Win 11 or Win 8.2 …

Code:
****************************************************************************************************************
FUNCTION Get_Version
****************************************************************************************************************
LOCAL lcMess AS String
DECLARE INTEGER GetVersion IN kernel32

DECLARE SHORT StrToIntEx IN Shlwapi;
	STRING pszString, INTEGER dwFlags, INTEGER @pllRet

lnVersion = GetVersion()

* The low-order word
lnVersionLo = BitRShift(BitLShift(lnVersion, 16), 16)
lcMess = "Major Version: "  + TRANSFORM(BitAnd(lnVersionLo, hex2dec("0x00ff"))) + CR_LF
lcMess = lcMess + "Minor Version: "  + TRANSFORM(BitRShift(BitAnd(lnVersionLo, hex2dec("0xff00")), 8)) + CR_LF+ CR_LF


* The high-order word
lnVersionHi = BitRShift(BitAnd(lnVersion, hex2dec("0xffff0000")), 16)
lcMess = lcMess + TRANSFORM(lnVersionHi)

MESSAGEBOX(lcMess)

FUNCTION  hex2dec (lcHex)
#DEFINE STIF_SUPPORT_HEX           1
	LOCAL lnRet
	lnRet = 0
	IF StrToIntEx (lcHex, STIF_SUPPORT_HEX, @lnRet) = 1
		RETURN lnRet
	ELSE
		RETURN 0
	ENDIF

Major = 6
Minor = 2
Version = 9200

As for OS(5), I always received 9200

I’m mystified….


 
All I want is to detect if my user have Windows 11

Thanks
 
Nro, I've just tried your code and am seeing the same as you.

OK, here is something else to try:

[tt]RUN SystemInfo >info.txt[/tt]

This will create a text file (named info.txt in the above example) that contains loads of information about the system. The second line contains the full name of the OS ("Microsoft Windows 10 Enterprise" in my case). The second line looks like it might contain the version number ("10" in my case).

I can't tell you what the equivalent text would be for Windows 11, but you can try it yourself and see. If it contains the information you need, you can use FILETOSTR() to get the text file into a variable, then parse out the required information.

Be warned that the above RUN command took a long time (about 20 seconds) on my system the first time I ran it, but it was much faster after that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Again, thanks Mike. I’ll put the run as soon as the user log, so the time impact is not that bad.
 
Nro,

You can instantiate a WMI Win32_OperatingSystem class and check the value of relevant properties.

Code:
LOCAL WMIService, MySytem, AllSystems
m.WMIService = GETOBJECT("winmgmts:\\.\root\cimv2")

m.AllSystems = m.WMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem",,48)

FOR EACH m.MySytem IN m.AllSystems

	? "Caption:", m.MySytem.Caption
	? "Version:", m.MySytem.Version
	? "BuildNumber:", m.MySytem.BuildNumber

ENDFOR
 
Hi Nro,

on Windows 8 and above, You must use RtlGetVersion function:

RtlGetVersion function: Link [URL unfurl="true"]https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlgetversion[/url]

OSVERSIONINFOW structure: Link [URL unfurl="true"]https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfow[/url]



Code:
FUNCTION b32_2_char( intVal )		&& assemble structure
	LOCAL intLo
	LOCAL intHi
	LOCAL charVal
	
	intLo = INT( intVal % 65536 )
	intHi = INT( intVal / 65536 )
	
	charVal = CHR( INT( intLo % 256 ) );
			+ CHR( INT( intLo / 256 ) );
			+ CHR( INT( intHi % 256 ) );
			+ CHR( INT( intHi / 256 ) )
			
	RETURN charVal
ENDFUNC

FUNCTION char_2_b32( charVal )		&& disassemble structure
	LOCAL lenVal
	LOCAL b32Val
	
	lenVal = LEN( charVal )
	
	IF lenVal != 4
		messText = "Error: char_2_b32!"
		
		MESSAGEBOX( messText, 0 + 16 )
		
		RETURN 0
	ENDIF
	
	b32Val = ASC( SUBSTR( charVal, 1, 1 ) );
		   + ASC( SUBSTR( charVal, 2, 1 ) ) * 256;
		   + ASC( SUBSTR( charVal, 3, 1 ) ) * 256 * 256;
		   + ASC( SUBSTR( charVal, 4, 1 ) ) * 256 * 256 * 256
		   
	RETURN b32Val
ENDFUNC

FUNCTION GetWindowsVersion()
	LOCAL osVersionInfo
	LOCAL majorVer
	LOCAL minorVer
	LOCAL buildNo
	LOCAL ret
	
	osVersionInfo = b32_2_char( 148 ) + SPACE( 144 )
	
	DECLARE INTEGER RtlGetVersion IN NTDLL.DLL;
			STRING @osVersionInfo
			
	ret = RtlGetVersion( @osVersionInfo )
	
	IF ret = 0x00000000
		majorVer = char_2_b32( SUBSTR( osVersionInfo, 5,  4 ) )
		minorVer = char_2_b32( SUBSTR( osVersionInfo, 9,  4 ) )
		buildNo  = char_2_b32( SUBSTR( osVersionInfo, 13, 4 ) )
	ENDIF
ENDFUNC



this should work :)

Regards, Stefan
 
hello guys. Thanks for these answer. Atlopes, your code is exactly what I want.

Thanks again
Nro

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top