Code:
alias envar {  
  if !$1 { return }  
  if $com(a) { .comclose a }  
  .comopen a WScript.Shell  
  if $comerr { return }  
  var %a $com(a,ExpandEnvironmentStrings,3,bstr,$iif($+($chr(37),*,$chr(37)) !iswm $1,$+($chr(37),$1,$chr(37)),$1))  
  %a = $iif($left($com(a).result,1) != $chr(37),1,0)   
  return $iif($prop == value,$iif(%a == 0,%a,$com(a).result),%a)  
  .comclose a
}

//echo -a $envar(windir) - returns 1
//echo -a $envar(random) - returns 0
it can't be retrieved the same way as %windir% for some reason.