Updated 2016-05-22 19:27:41 by bll

This code detects the operating system name on windows.

Sources:

namespace eval windows_os {

    array set desktop_versions {
        10.0 {Windows 10}
        6.3 {Windows 8.1}
        6.2 {Windows 8}
        6.1 {Windows 7}
        6.0 {Windows Vista}
        5.2 {Windows XP 64-Bit Edition}
        5.1 {Windows XP}
        5.0 {Windows 2000}
    }
    
    
    proc windows_name {} {
        if {$::tcl_platform(platform) eq "windows"} {
            variable desktop_versions
            
            package require registry
            
            if {[catch {
                set major_version [registry get {HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion} CurrentMajorVersionNumber]
                set minor_version [registry get {HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion} CurrentMinorVersionNumber]
            }]} {
                set windows_version [registry get {HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion} CurrentVersion]
            } else {
                set windows_version $major_version.$minor_version
            }
            
            return $desktop_versions($windows_version)
        } else {
            error "Operating system is not windows"
        }
    }
    
}

See also: tcl_platform
set windows_version $::tcl_platform(osVersion)

But note that tcl_platform(osVersion) may not be completely reliable with old Tcl versions on new windows platforms due to Windows API artifacts.