; MemoryCheckByRegistry.kix
break on
$=setoption("WrapAtEOL","on")
? memory()
function memory(optional $remotepc)
dim $hexdmp, $hex, $counter, $hexvals, $memkey, $vals
if $remotepc=""
$remotepc='\\'+ @wksta
else
if not left($remotepc,2)="\\"
$remotepc='\\' + $remotepc
endif
endif
$memkey="\HKEY_LOCAL_MACHINE\hardware\resourcemap\system resources\physical memory"
$hexdmp=readvalue($remotepc + $memkey,".Translated")
for $start = 1 to len($hexdmp) step 8
$hex=""
for $counter = 0 to 7 step 2
$hex=substr($hexdmp,$start + $counter,2)+$hex
next
if $hexvals=""
$hexvals=$hex
else
$hexvals=$hexvals + "|" + $hex
endif
next
$vals=split($hexvals,"|")
for $counter= 8 to 16 step 4
$memory=$memory + hextodec($vals[$counter])/1024
next
$memory=($memory +648)/1024
endfunction
Function HexToDec($Hex)
; Convert Hex to decimal
; If the hex number is <= 7FFFFFFF the funtion returns an Integer
; If the hex number is > 7FFFFFFF the funtion returns the string representation of the integer value
; by use of the UDF: HexToDecStr()
$HexArr = "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"," "
If $Hex > "7FFFFFFF" ; Will result in overflow, convert to "integer string" instead
$HexToDec = HexToDecStr($Hex)
Return
EndIf
$HexToDec = 0
$Fac = 1
For $L = Len($Hex) To 1 Step -1
$Ch = SubStr($Hex, $L, 1)
$nb = 0
While $Ch <> $HexArr[$nb] And $nb < 16
$nb = $nb + 1
Loop
If $nb = 16 ; Error in hex-string, contains non-valid characters
$HexToDec = 0
Return
EndIf
$HexToDec = $HexToDec + $nb * $Fac
$Fac = $Fac * 16
Next
EndFunction
Function HexToDecStr($Hex)
; Convert Hex-number to stringrepresentation af integer value
; Using UDF's:
; HexToBinStr()
; StrAdd()
; StrMult2()
$BinStr = HexToBinStr($Hex) ; Convert Hex to binary string
$BinVal = "1" ; Decimal stringvalue for first Binary digit
$HexToDecStr = "0"
For $L = Len($BinStr) To 1 Step -1
$Cif = SubStr($BinStr, $L, 1)
If $Cif = "1" ; "Add decimal stringvalues for Binary digits"
$HexToDecStr = StrAdd($HexToDecStr, $BinVal)
EndIf
$BinVal = StrMult2($BinVal) ; Create decimal stringvalue for next binary digit
Next
EndFunction
Function HexToBinStr($Hex)
; Convert Hex-number to binary string
$HexArr = "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"," "
$BinArr = "0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"
$HexToBinStr = ""
For $L = Len($Hex) To 1 Step -1
$Ch = SubStr($Hex, $L, 1)
$nb = 0
While $Ch <> $HexArr[$nb] And $nb < 16
$nb = $nb + 1
Loop
If $nb = 16 ; Error in hex-string, contains non-valid characters
$HexToBinStr = "0"
Return
EndIf
$HexToBinStr = $BinArr[$nb] + $HexToBinStr
Next
While SubStr($HexToBinStr, 1, 1) = "0"
$HexToBinStr = SubStr($HexToBinStr, 2, Len($HexToBinStr) - 1)
Loop
EndFunction
Function StrAdd($Str1, $Str2)
; Add Strings, treat as integers
$StrAdd = ""
$Carry = 0
While Len($Str1) < Len($Str2)
$Str1 = "0" + $Str1
Loop
While Len($Str2) < Len($Str1)
$Str2 = "0" + $Str2
Loop
For $L = Len($Str1) To 1 Step -1
$Cif1 = Val(SubStr($Str1, $L, 1))
$Cif2 = Val(SubStr($Str2, $L, 1))
$CifSum = $Cif1 + $Cif2 + $Carry
$CifSumStr = "" + $CifSum
$StrAdd = SubStr($CifSumStr, Len($CifSumStr), 1) + $StrAdd
If Len($CifSumStr) > 1
$Carry = Val(SubStr($CifSumStr, 1, 1))
Else
$Carry = 0
EndIf
Next
If $Carry
$StrAdd = "" + $Carry + $StrAdd
EndIf
EndFunction
Function StrMult2($MultStr)
; Mutiply string by 2, treat as integer
$StrMult2 = ""
$Carry = 0
For $L = Len($MultStr) To 1 Step -1
$CifVal = Val(SubStr($MultStr, $L, 1)) * 2 + $Carry
$CifStr = "" + $CifVal
$StrMult2 = SubStr($CifStr, Len($CifStr), 1) + $StrMult2
If Len($CifStr) > 1
$Carry = 1
Else
$Carry = 0
EndIf
Next
If $Carry
$StrMult2 = "1" + $StrMult2
EndIf
EndFunction
|