WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

dotNet
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

dotNet Version UDFs

 Keywords: dotNet .Net Version UDFs Install Exist List Get Service Pack 

;***************************************************************************
;**            Installed dotNet Version Details
;**
;** Queries the information from the registry
;**
;** Currently supported version values = 4.5, 4.0, 3.5, 3.0, 2.0.50727, 1.1.4322
;**
;** Developer: Deana Falk 2014.05.09
;***************************************************************************

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;        udfdotNetGetVersionInfo( nVersion, sOther )
;        Gets the installed versions, service packs and other from registry
;
; Parameters:      nVersion: Version number to check
;                  sOther: Specifies registry subkey: i.e. "client" of "full".
; Return Value:    delimited list containing (Version|Service Pack|Other) or "" if not installed.
;
; Note: Does not currently handle 1.0 versions, because that can get a bit complicated.
; http://blogs.msdn.com/b/deva/archive/2010/12/10/how-to-determine-which-microsoft-net-framework-version-and-service-pack-installed.aspx
;
; Currently supported version values = 4.5, 4.0, 3.5, 3.0, 2.0.50727, 1.1.4322
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#DefineFunction udfdotNetGetVersionInfo(sVersion, sOther)

   If sVersion > 4.5
       Pause('udfdotNetVersionsExist','This function does not currently support checking this dotNet Version.')
       Return 0
   EndIf
   sSubkey = ""
   sSPDataItem = ""
   sSp = ""
   keyhandle = @REGMACHINE
   If WinMetrics(-7)|WinMetrics(-2)==3
      RegOpenFlags( 64 )
   Else
      RegOpenFlags( 32 )
   EndIf

   ;https://its-knowledge01.campus.ad.csulb.edu/display/help/How+to+check+the+version+of+.NET+that's+Installed
   Switch @TRUE
      Case sVersion == "4.5"
      Case sVersion == "4.0"
         sSubkey =  "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\" : sOther
         sSPDataItem = "Servicing"
         Break
      Case sVersion == "3.5"
         sSubkey =  "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5"
         sSPDataItem = "SP"
         Break
      Case sVersion == "3.0"
         sSubkey =  "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0"
         sSPDataItem = "SP"
         Break
      Case sVersion == "2.0.50727"
         sSubkey =  "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727"
         sSPDataItem = "SP"
         Break
      Case sVersion == "1.1.4322"
         sSubkey = "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322"
         sSPDataItem = "SP"
         Break
   EndSwitch

   If RegExistValue( keyhandle, sSubkey:'[Version]' )
      sVersion = RegQueryValue( keyhandle, sSubkey:'[Version]' )
   EndIf

   If RegExistValue( keyhandle, sSubkey:'[':sSPDataItem:']')
      sSP = RegQueryDword( keyhandle, sSubkey:'[':sSPDataItem:']' )
   EndIf

   sResult = sVersion:"|":sSP:"|":sOther
   If sResult == "||" Then sResult = ""
   Return sResult
#EndFunction

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;        udfdotNetVersionsList()
;        Returns a list of all the installed versions, service packs, and other
;
; Parameter:       None.
; Return Value:    Tab delimited list containing (Version|Service Pack|Other) or "" if not installed.
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#DefineFunction udfdotNetVersionsList()
   sList = ''
   sDelim = '|'

   sValue = udfdotNetGetVersionInfo("4.5", "Full")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("4.5", "Client")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("4.0", "Full")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("4.0", "Client")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("3.5", "")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("3.0", "")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("2.0.50727", "")
   sList = sList : sValue :  @TAB

   sValue = udfdotNetGetVersionInfo("1.1.4322", "")
   sList = sList : sValue

   Return sList
#EndFunction


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;        udfdotNetVersionsExist(sVersion)
;        Determines if a specific version of dotNet is installed.
;
; Parameter:       sVersion. Supported values = 4.5, 4.0, 3.5, 3.0, 2.0.50727, 1.1.4322
; Return Value:    @True if installed; @False otherwise.
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#DefineFunction udfdotNetVersionsExist(sVersion)
   If sVersion > 4.5
       Pause('udfdotNetVersionsExist','This function does not currently support checking this dotNet Version.')
       Return 0
   EndIf
   If sVersion == "4.0" || sVersion == "4.5"
      sValue = udfdotNetGetVersionInfo(sVersion, "Full")
   Else
      sValue = udfdotNetGetVersionInfo(sVersion, "")
   EndIf
   If sValue == "" Then bResult = 0
   Else bResult = 1
   Return bResult
#EndFunction

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
;        udfdotNetLastestVersion()
;        Gets the latest version of dotNet that is installed.
;
; Parameter:       None
; Return Value:    delimited list containing (Version|Service Pack|Other) of the latest version of dotNet installed.
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#DefineFunction udfdotNetLastestVersion()
   lastversion = ItemExtract( 1, udfdotNetVersionsList(), @TAB )
   Return lastversion
#EndFunction

;***************************************************************************
;***************************************************************************
;***************************************************************************

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Check a specific dotNet version exists
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sVer = "4.0"
sRet = udfdotNetVersionsExist(sVer)
If sRet
   Pause('dotNet Version ':sVer,'Is Installed.')
Else
   Pause('dotNet Version ':sVer,'Not Installed.')
EndIf

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; List all installed dotNet Versions
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strList = udfdotNetVersionsList()
AskItemlist( 'dotNet Installed Version Details', strList, @TAB, @UNSORTED, @SINGLE )

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Determine Latest dotNet Version installed
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lastversion = udfdotNetLastestVersion()
Pause('Latest installed dotNet version details',lastversion)
Exit

Article ID:   W17802
Filename:   dotNet Version UDFs.txt
File Created: 2014:05:09:11:43:06
Last Updated: 2014:05:09:11:43:06