User Tools

Site Tools


userspace:library:getos

Library: GetOS

Tested with opsi 4.0.2
required WInst Version: 4.11.3
By Frank Thommen, 2014/04/24 20:25

Tree:

%SCRIPTDRIVE%\lib\
  └ GetOS.sub

GetOS.sub

;
; -----------------------------------------------------------
;  GetOS.sub - Retrieve the current OS version
; -----------------------------------------------------------
;
; AUTHOR: Frank Thommen, EMBL Heidelberg
; SHORTNAME (for variable names): os
;
;
; PREREQUISITE: none
;
; RETURN VARIABLE: $_os
;
; PURPOSE: Retrieve the current OS version using a consistent
;          naming "Win"+version, where version can be one of
;             XP
;             Vista
;             7
;             8
;             8.1
;
;          The OS version is returned in the variable $_os.  The
;          default value of $_os is "UNKNOWN".
;
;
; NOTE: This script implements the informations published at
;       http://msdn.microsoft.com/en-us/library/ms724833%28VS.85%29.aspx
;       and in the chapter "7.4.1. Info Maps" of the OPSI Winst manual
;       for version 4.11.3.  HOWEVER, only a SUBSET of the possible
;       OS versions is supported (see above).
;
;
; USAGE:
;          Sub "%SCRIPTDRIVE%\lib\GetOS.sub"
;          if ($_os = "UNKNKOWN")
;             PAUSE "This is OS is UNKNOWN"
;          else
;             PAUSE "OS is " + $_os
;          endif
;
;
; HISTORY: 2013:        Initial version
;          12-FEB-2014: Added Windows 8 and 8.1 support
;
;
 
; avoid error message if run several times
ScriptErrorMessages = off
FatalOnSyntaxError  = false
  DefVar $_os
  Set    $_os = "UNKNOWN"
 
  DefStringList $__MSVersionMap
  Set           $__MSVersionMap = getMSVersionMap
 
  DefVar $__os.majorversion
  Set    $__os.majorversion = getValue("major_version", $__MSVersionMap)
 
  DefVar $__os.minorversion
  Set    $__os.minorversion = getValue("minor_version", $__MSVersionMap)
 
  ; ProductType:
  ;   1 = VER_NT_WORKSTATION
  ;   2 = VER_NT_DOMAIN_CONTROLLER
  ;   3 = VER_NT_SERVER
  ;
  DefVar $__os.producttype
  Set    $__os.producttype = getValue("product_type_nr", $__MSVersionMap)
ScriptErrorMessages = on
FatalOnSyntaxError  = true
 
 
if ( $__os.producttype = "1" )
  ; Client OS versions
  ;
  if ( $__os.majorversion = "6" )
    if ( $__os.minorversion = "3")
      Set $_os = "Win8.1"
    else
      if ( $__os.minorversion = "2")
        Set $_os = "Win8"
      else
        if ( $__os.minorversion = "1")
          Set $_os = "Win7"
        else
          if ( $__os.minorversion = "0")
            Set $_os = "WinVista"
          endif
        endif
      endif
    endif
  else
    if ( $__os.majorversion = "5" )
      ; this detection is a pragmatic approach as the
      ; detecting Win XP Pro 64bit is more complicated
      ; (see http://msdn.microsoft.com/en-us/library/ms724833%28VS.85%29.aspx) 
      Set $_os = "WinXP"
    endif
  endif
endif
userspace/library/getos.txt · Last modified: 2021/08/23 08:37 (external edit)