OSVersion Property (.NET)

Type: String

OSVersion returns the version of the installed operating system. Possible return values include "9.2.2", "10.1", "10.3.9", "10.4", "10.4.2" (in the case of a MacOS), "4.0", "4.1", "4.9", "5.0", "5.1", "5.2", and "6.0" (in the case of Windows) and other values with other operating systems.

 

Details on the possible return results follow:

 

Mac OS: Specific for Mac OS, the following table can be used to translate the Mac OS version to the corresponding Mac OS product name:

OSVersion Product Name

"9.0"  Mac OS 9

"10.0"  Cheetah

"10.1"  Puma

"10.2"  Jaguar

"10.3"  Panther

"10.4"  Tiger

'10.5"  Leopard

 

Note: Results typically include a "dot release" in the version. For example "10.4", or "10.4.1" or "10.4.2". Therefore make sure your string comparisons take this into account. For example do not use OSversion = "10.4" since that will not return true for any 10.4.x subversion returned. Use the CompareVersions method to make it easy to check for a minimum version number you require.

 

Windows: The following table can be used to translate the OSVersion to a Windows product name for Windows based operating systems. Note that the OSName property returns these results for you.

OSVersion Product Name

"4.0"  Windows 95

"4.1"  Windows 98

"4.9"  Windows ME

"5.0"  Windows 2000

"5.0 build 0" Windows CE

"5.1"  Windows XP

"5.2"  Windows 2003 Server

"6.0"  Windows Vista

 

Special notes for this property:

 

Note: Use of this property requires the Enterprise Edition of BrowserHawk.

 

Example 1 - General Demonstration:

This example shows how to get the OSName and OSVersion properties, and displays the results for demonstration purposes:

<%

ExtendedOptions options = new ExtendedOptions();

options.AddProperties("OSName, OSVersion");

ExtendedBrowserObj extBrow = BrowserObj.GetExtendedBrowser(options);

%>

<html>

<% if (extBrow.OSName == "-1" || extBrow.OSName == "-2") {

// Fall back to use the Platform property when OSName is not available

Response.Write("OSName: Not available");

BrowserObj browObj = BrowserObj.GetBrowser();

Response.Write(" (Platform property is " + browObj.Platform + ") <p>");

} else {

Response.Write("OSName: " + extBrow.OSName + "<p>");

}

 

if (extBrow.OSVersion == "-1" || extBrow.OSVersion == "-2")

Response.Write("OSVersion: Not available");

else

Response.Write("OSVersion: " + extBrow.OSVersion);

%>

</html>

 

Example 2 - Detecting Mac OS version:

This example shows how to use the OSName and OSVersion properties to check for Mac OS X version 10.4.2 or higher. For purposes of this example, any Mac users with a version prior to 10.4.2 is redirected to another page.

<%

// First check to see if they are even on a Mac.

// If not we can bypass these tests so that non-Mac users (Windows users

// for example) are not even tested for OSName and OSVersion which

// maximizes the efficiency of our code.

BrowserObj browObj = BrowserObj.GetBrowser();

if (browObj.Platform.Substring(0,3) == "Mac") {

ExtendedOptions options = new ExtendedOptions();

options.AddProperties("OSVersion");

ExtendedBrowserObj extBrow = BrowserObj.GetExtendedBrowser(options);

string osver = extBrow.OSVersion;

if (osver == "-1" || osver == "-2") {

// result of OSVersion is unavailable - handle this situation as you wish

} else {

// Check to see if they have Mac OS X 10.4.2 or higher.

// We use the CompareVersions method to check the version number

// since it makes numeric comparisons with strings very easy.

if (BrowserObj.CompareVersions(osver, "10.4.2") < 0) {

// user has Mac OS prior to OS X 10.4.2, redirect them to another page

Response.Redirect("/old_mac_users.aspx");

}

}

}

%>

<html> Page for all users except those with Mac OS prior to 10.4.2 goes here </html>

 

See Also:

Additional Steps Required for Java based properties

Detecting Operating System Details

OSArch Property (.NET)

OSName Property (.NET)

Platform Property (.NET)

CompareVersions Method (.NET)