>>Hi,
>>
>>I want to write a function that gives me the OS of the computer ie Windows 98 / Windows NT etc.
>>
>>OS(1) function returns Win version number as 4 for Win 98, 4.9 for Win Me, 5 for Win 2000 and so on. Is there any way I can map the return value of OS(1) to the correct equivalent Windows OS version?
>
>A DO CASE, that returns exactly the value you want. Or, define constants for each version of Windows.
>
>The main problem is to get the complete list of OS.
Another option would be to implement the Win32 API GetVersionEx() API call; at a minimum, it will return an OSVERSIONINFO structure that contains the major and minor OS versions, build number and may contain a CSD string providing further differentiation; WinNT 4.0 SP6 and later can provide an extended version of the structure OSVERSIONINFOEX which contains service pack detail as well. Both structures are relatively simple, and well-documented in the MSDN documentation; the call to GetVersionEx() is pretty straightforward - create a big buffer in a VFP memory variable and pass it by reference, and then parse the return value:
DECLARE SHORT GetVersionEx IN WIN32API STRING @ lpBuffer
cOSVERSIONINFOBuffer = CHR(147) + REPL(CHR(0),147)
IF GetVersionEx(@cOSVERSIONINFOBuffer) # 0
ELSE
ENDIF
If you discover that a compatible OS is present, you can repeat the call with a buffer of 156 bytes in length to retrieve the OSVERSIONINFOEX structure. The OSVERSIONINFO strucutre is simple - 5 DWORDs, representing the structure size, major version, minor version, build number, and platform ID respectively, followed by 128 bytes of CSD data treated as a CString. You'll need a UDF to convert 4 byte strings to numeric values (you can use DWORDToNum() from CLSHeap, which can be downloaded from the Files section, or any of a number of other published UDFs to do this) and will need to use the reference data from the OSVERSIONINFO structure documentation in the MSDN Library (if you don't have it on CD, it's available online via msdn.microsoft.com in the documentation on the Platform SDK.)
VFP's OS(1) should be able to be used to get a simple differentiation of OS version if build issues are not important.