BradV
(Seasoned Scripter)
2016-03-04 05:44 PM
get xml version

I didn't find a script in the UDF library. So, I started writing one. I'm having a problem with it on Windows 2008 R2 servers. The EnumValue doesn't seem to work even though I can see the value in regedit.

 Code:
Function GetXMLVersion(optional $strComputer)
   DIM $strKey, $intIndex, $intI, $strValName, $arrVer[10]
   If $strComputer = ""
      $strComputer = "."
   EndIf
   ;
   $strKey="\HKEY_CLASSES_ROOT\CLSID\{2933BF90-7B36-11D2-B20E-00C04F983E60}\VersionList"
   $intIndex = 0
   $intI     = 0
   If KeyExist("\\" + $strComputer + $strKey)
      $strValName = EnumValue("\\" + $strComputer + $strKey, $intIndex)
      While Not @ERROR
         If $strValName <> "(Default)"
            ; Want to ignore the Default entry
            $arrVer[$intI] = $strValName
            $intI = $intI + 1
         EndIf
         $intIndex = $intIndex + 1
         $strValName = EnumValue("\\" + $strComputer + $strKey, $intIndex)
      Loop
   EndIf
   ; To mark the end of the array, place a -1 in the next array position.
   $arrVer[$intI] = -1
   $GetXMLVersion = $arrVer
EndFunction

It works fine on 32 bit Windows Server 2003.


Glenn BarnasAdministrator
(KiX Supporter)
2016-03-04 05:54 PM
Re: get xml version

$ = SetOption(AlternateRegView', 'Off') may be your best friend...

Glenn

PS - the command is from memory - please confirm in the ReadMe or User Guide! \:D


BradV
(Seasoned Scripter)
2016-03-04 07:29 PM
Re: get xml version

Hi Glenn,

That was it (WOW64AlternateRegView). Now, that worked when run locally on that server. If I am running from a central server, how do I set that on the 64 bit systems and not on the 32 bit systems? Or, will the 32 bit systems just ignore it? So, having it on always won't hurt?

Regards,

Brad


Glenn BarnasAdministrator
(KiX Supporter)
2016-03-04 09:38 PM
Re: get xml version

Won't affect x86 (since there is no alternate view) or remote queries. \:\)

Glenn


ChristopheM
(Hey THIS is FUN)
2016-03-05 04:21 PM
Re: get xml version

here is a complete version of the function with few optimizations and real size for the array.
 Code:
Function GetXMLVersion(optional $strComputer)
  redim $GetXMLVersion[10]
  dim $oldopt, $strKey, $intI

  $strKey="HKEY_CLASSES_ROOT\CLSID\{2933BF90-7B36-11D2-B20E-00C04F983E60}\VersionList"

  If vartype($strComputer) = 0  $strComputer = ""   EndIf
  If $strComputer  $strKey = "\\"+$strComputer+"\"+$strKey   EndIf

  $oldopt = SetOption( "WOW64AlternateRegView", "Off")
  $intI = -1
  If KeyExist( $strKey )
    dim $intIndex, $strValName

    $intIndex = 0
    $strValName = EnumValue( $strKey, $intIndex )
    While Not @ERROR
      If $strValName <> ""
        ; Want to ignore the Default entry
        $intI = $intI + 1
        if $intI > UBound($GetXMLVersion)
          redim preserve $GetXMLVersion[UBound($GetXMLVersion)*2]
        endif
        $GetXMLVersion[$intI] = $strValName
      EndIf
      $intIndex = $intIndex + 1
      $strValName = EnumValue( $strKey, $intIndex)
    Loop
  EndIf
  $oldopt = SetOption( "WOW64AlternateRegView", $oldopt )

  if $intI=-1     exit 1    endif

  redim  preserve $GetXMLVersion[$intI]
  exit 0
EndFunction

;--------------------------------
;  demo
;--------------------------------
$arrVers = GetXMLVersion()
if not @error
  for each $vers in $arrVers
    $vers ?
  next
endif
The main change is that the returned array has no -1 value at the end. you just need to test the macro @error. There is also one optimization for local access (no \\.\) and one optimization on string concatenation (strKey include \\$strcomputer\ when remote access).