Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to determine OS?
Message
From
27/05/2002 09:04:23
 
 
To
27/05/2002 08:31:11
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00661640
Message ID:
00661656
Views:
15
>>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) && get an OSVERSIONINFO
IF GetVersionEx(@cOSVERSIONINFOBuffer) # 0
   *  It worked
ELSE
   * it failed - call GetLastError() to find out why
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.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform