;NAME disk_info.kix
;
;DESCRIPTION This is a script to retrieve disk information for a given computer.
;
;AUTHOR Brad Van Orden
;
;VERSION 1.5
;
;HISTORY Created 24 Jul 07
; 29 Aug 07 - Added a subroutine to change bytes into MBs or GBs
;
Break On
;
Dim $SO
;
; These are just programming options for me.
; One forces me to define all variables and the
; other doesn't allow a kixtart macro within a string.
;
$SO = SetOption('Explicit', 'On')
$SO = SetOption('NoMacrosInStrings', 'On')
;
DIM $strComputer, $objWMIService, $colDisks, $objDisk, $arrDisk[4,0]
DIM $intCount, $strFile, $intErr, $strType, $strSiz
;
$strComputer = "."
While $strComputer == "."
? "Please enter the name of the workstation:"
Gets $strComputer
Loop
; Make sure no leading or trailing spaces were accidently added to the name.
;
$strComputer = Trim($strComputer)
;
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
If @ERROR <> 0
? "Could not map to the Windows Management Instrumentation object for computer, " + $strComputer
exit 1
Else
$strFile = "C:\Documents and Settings\" + @userid + "\Desktop\" + $strComputer + "_disk_info.ini"
$intCount = 0
$colDisks = $objWMIService.ExecQuery("Select * FROM Win32_LogicalDisk")
For Each $objDisk in $colDisks
ReDim Preserve $arrDisk[4,$intCount]
Select
Case $objDisk.DriveType = "2"
$arrDisk[0,$intCount] = "This device is a floppy drive."
$strType = "Floppy Drive"
Case $objDisk.DriveType = "3"
$arrDisk[0,$intCount] = "This device is a hard drive."
$strType = "Hard Drive"
Case $objDisk.DriveType = "4"
$arrDisk[0,$intCount] = "This device is a mapped network drive."
$strType = "Mapped Network Drive" + $intCount
Case $objDisk.DriveType = "5"
$arrDisk[0,$intCount] = "This device is a CD or DVD drive."
$strType = "CD/DVD Drive"
Case 1
$arrDisk[0,$intCount] = "Note sure what this device type is: " + $objDisk.DriveType
$strType = "Unknown"
EndSelect
$arrDisk[1,$intCount] = $objDisk.DeviceID
$arrDisk[2,$intCount] = $objDisk.FileSystem
$arrDisk[3,$intCount] = $objDisk.FreeSpace
$arrDisk[4,$intCount] = $objDisk.Size
If $objDisk.DriveType <> "4"
? "This device type is " + $strType
? "The drive letter of this device is " + $arrDisk[1,$intCount]
$intErr = WriteProfileString($strFile,$strType,"Device ID",$arrDisk[1,$intCount])
If $arrDisk[2,$intCount] <> ""
? "The file system type is " + $arrDisk[2,$intCount]
EndIf
$intErr = WriteProfileString($strFile,$strType,"File System Type",$arrDisk[2,$intCount])
If $arrDisk[3,$intCount] <> ""
$strSiz = Join(MagQ($arrDisk[3,$intCount]),"")
? "The amount of free space on this disk is " + $strSiz
EndIf
$intErr = WriteProfileString($strFile,$strType,"Free Space",$strSiz)
If $arrDisk[4,$intCount] <> ""
$strSiz = Join(MagQ($arrDisk[4,$intCount]),"")
? "The total disk space is " + $strSiz
EndIf
$intErr = WriteProfileString($strFile,$strType,"Disk Size",$strSiz)
EndIf
$intCount = $intCount + 1
$strSiz = ""
Next
EndIf
Sleep 5
;
;Function: MagQ()
;
;Author: Brad Van Orden
;
;Version: 1.0
;
;History Created 23 Aug 07
;
;Action: Takes in a number and returns it quantified to the appropriate magnitude prefix.
;
;Syntax: MagQ($intSize)
;
;Parameters: intSize - The number we wish to quantify.
;
;Returns: Two-dimensional array as follows:
; 0 - Computed Size
; 1 - Size Prefix
;
Function MagQ($intSize)
;
Dim $arrRes[1], $GIGA, $MEGA, $KILO
;
$KILO = 1024.
$MEGA = $KILO * $KILO
$GIGA = $MEGA * $KILO
;
Select
Case $intSize > $GIGA
$arrRes[0] = (1. * CINT((CDBL($intSize)/$GIGA)*100))/100.
$arrRes[1] = "GB"
Case $intSize > $MEGA
$arrRes[0] = (1. * CINT((CDBL($intSize)/$MEGA)*100))/100.
$arrRes[1] = "MB"
Case $intSize > $KILO
$arrRes[0] = (1. * CINT((CDBL($intSize)/$KILO)*100))/100.
$arrRes[1] = "KB"
EndSelect
$MagQ = $arrRes
EndFunction