matzas
(Fresh Scripter)
2011-01-19 10:58 AM
unable to get the int value...

hi,

i use the folowing script for getting the disk size + free size.

 Code:
$computer  = "."
$objWMIService = GetObject( "winmgmts://" + $computer + "/root/CIMV2" )
  $colDisks = $objWMIService.ExecQuery("Select * FROM Win32_LogicalDisk")
For Each $objDisk in $colDisks
   Select
      Case $objDisk.DriveType = "2"
        $Devtype = "floppy drive." 
      Case $objDisk.DriveType = "3"
        $DevType = "hard drive."
	? " "
        ? " Drive: " + $objDisk.Name
        ? " Device type:................" + $DevType
	? " File System:................" + $objDisk.FileSystem
	$dfs=CInt ($objDisk.FreeSpace)
        $dds=Cint ($objDisk.Size)
	$sss= $dds - $dfs
        ? " Free Space:................." + $objDisk.FreeSpace + " / " + $objDisk.Size
	? "amir : " + $sss + " - " + $dfs + " - " + $dds
	? " "

      Case $objDisk.DriveType = "4"
        $DevType = "mapped network drive."
      Case $objDisk.DriveType = "5"
        $DevType = "CD or DVD drive."
		? " "
        ? " Drive: " + $objDisk.Name
        ? " Device type:................" + $DevType
	    ? " "	  
      Case 1
        $DevType = "Unknown"
   EndSelect


the result i get:

Drive: C:
Device type:................hard drive.
File System:................NTFS
Free Space:.................229501284352 / 319697539072
amir : 0 - 2147483647 - 2147483647

why i get the number 2147483647 instead of: 229501284352 ??
how can i get the real numbers at the free space?? and do some math on them??

thanks...


BradV
(Seasoned Scripter)
2011-01-19 01:06 PM
Re: unable to get the int value...

Hi Matzas,

Well, I would guess since you are rounding the numbers to an integer when setting $dfs and $dds. What happens if you remove the cint from each line? Does $sss become 90196254720?


matzas
(Fresh Scripter)
2011-01-19 02:39 PM
Re: unable to get the int value...

thanks for your answer....
when i remove the cint from both of the lines i get an error in the kix script...

when i remark the line "$sss= $dds - $dfs" i see the real value...

the result are:
Drive: C:
Device type:................hard drive.
File System:................NTFS
Free Space:.................213 GB
Free Space:.................229491920896 / 319697539072
amir : - 229491920896 - 319697539072

but i can't do any math activities...

how do i asure that the values in $dds and in $dfs are numbers and not strings?.. (is that the problem??)


please help.

thanks.,


Richard H.Administrator
(KiX Supporter)
2011-01-19 02:52 PM
Re: unable to get the int value...

No, the problem is that you are exceeding the maximum value that KiXtart can handle. The numbers are too big.

One simple solution is just to drop the last 3 digits from the string to scale the number as kilobytes (give or take) and then convert to numeric. This is often close enough.

This problem comes up with disk drive sizes quite regularly, if you search the forums you will find other suggestions for workarounds.