Wiki Home

VFP Function OS


Namespace: WIN_COM_API

THE VFP OS() function returns the name and version number of the operating system under which Microsoft Visual FoxPro is running.

The values returned by OS() function are listed below:
Operating System Return Value Comment
Windows 95 Windows 4.00
Windows 98 Windows 4.10
Windows 98 SE Windows 4.10
Windows ME Windows 4.90
Windows NT 4.0 Windows NT 4.00
Windows 2000 Windows 5.00 or Windows NT 5.00 MSKB Q250512 Offsite link to http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q250512
Windows XP Windows 5.01
Windows Server 2003 Windows 5.02
Windows Vista Windows 6.00 OS(5) returns "6000"
Windows Vista SP1 Windows 6.00 OS(5) returns "6001" AND OS(11) returns "1"
Windows Vista SP2 Windows 6.00 OS(5) returns "6002" AND OS(11) returns "1"
Windows Server 2008 Windows 6.00 OS(5) returns "6001" AND OS(11) returns "2" or "3"
Windows Server 2008 SP2 Windows 6.00 OS(5) returns "6002" AND OS(11) returns "2" or "3"
Windows 7 Windows 6.01 OS(5) returns "7600" AND OS(11) returns "1"
Windows 7 SP1 Windows 6.01 OS(5) returns "7601" AND OS(11) returns "1"
Windows Server 2008 R2 Windows 6.01 OS(5) returns "7600" AND OS(11) returns "2" or "3"
Windows Server 2008 R2 SP1 Windows 6.01 OS(5) returns "7601" AND OS(11) returns "2" or "3"
Windows 8 Dev Preview Windows 6.02 OS(5) returns "8102" AND OS(11) returns "1"
Windows 8 (Release) Windows 6.02 OS(5) returns "9200" AND OS(11) returns "1"
Windows 8.1 Windows 6.02 OS(5) returns "9200" (why not 9600?) AND OS(11) returns "1"
Windows 10 Windows 6.02 OS(5) returns "9200" AND OS(11) returns "1"

Here's some useful code:

lcOS = OS(1)
DO CASE
CASE "6.02" $ lcOS AND OS(11) = "1"
	lcPlatform = "WIN8"
CASE "6.01" $ lcOS AND OS(11) = "1"
	lcPlatform = "WIN7"
CASE "6.01" $ lcOS
	lcPlatform = "WIN2008R2"
CASE "6.00" $ lcOS AND OS(11) = "1"
	lcPlatform = "VISTA"
CASE "6.00" $ lcOS
	lcPlatform = "WIN2008"
CASE "5.02" $ lcOS
	lcPlatform = "WIN2003"
CASE "5.01" $ lcOS
	lcPlatform = "WINXP"
CASE "5.0" $ lcOS
	lcPlatform = "WIN2000"
CASE "NT" $ lcOS
	lcPlatform = "WINNT"
CASE "4.0" $ lcOS OR "3.9" $ lcOS
	lcPlatform = "WIN95"
CASE "4.1" $ lcOS
	lcPlatform = "WIN98"
CASE "4.9" $ lcOS
	lcPlatform = "WINME"
CASE "3." $ lcOS
	lcPlatform = "WIN31"
OTHERWISE
	lcPlatform = "(Unknown)"
ENDCASE

DECLARE Long GetModuleHandle IN WIN32API STRING lpModuleName
DECLARE Long GetProcAddress IN WIN32API Long hModule, String lpProcName
llIsWow64ProcessExists = (GetProcAddress(GetModuleHandle("kernel32"),"IsWow64Process") <> 0)
llIs64BitOS = .F.
IF llIsWow64ProcessExists
	DECLARE Long GetCurrentProcess IN WIN32API
	DECLARE Long IsWow64Process IN WIN32API Long hProcess, Long @ Wow64Process
	lnIsWow64Process = 0
	* IsWow64Process function return value is nonzero if it succeeds
	* The second output parameter value will be nonzero if VFP application is running under 64-bit OS
	IF IsWow64Process( GetCurrentProcess(), @lnIsWow64Process) <> 0
		llIs64BitOS = (lnIsWow64Process <> 0)
	ENDIF	
ENDIF	
lcPlatform = lcPlatform+" "+IIF(llIs64BitOS,"(64-bit)","(32-bit)")

? lcPlatform


In addition to OS(1), what would one need to do to differentiate between Win98 and Win98 SE? - William Fields
You can use OS(5) to get build number. -- Sergey Berezniker
But this is only available in VFP 7.0+. For previous version see Get Windows Version -- Rick Bean
Haven't had an opportunity to test this yet, but here's another possibility: HOWTO: Determine the Operating System Build Number - http://support.microsoft.com/?id=188987 - William Fields. Get Windows Version uses the same Windows API but is more extensive.
Contributors: Sergey Berezniker, Cindy Winegarden, Carl Warner, Rick Bean
Category VFP Functions

Meta Description: Using the OS() function in Visual FoxPro
Meta Keywords: Windows versions, Visual FoxPro OS() function
( Topic last updated: 2013.10.27 03:12:08 PM )