Posted By

saqibmj on 10/03/12


Tagged

vbscript


Versions (?)

Function to get the Logical Disk Drive Memory Information.


 / Published in: Visual Basic
 

Function to get the Logical Disk Drive Memory Information.

  1. '-----------------------------------------------------------------------------------------------------------------------------------
  2. ' Function : DiskUse(string)
  3. ' Description : This Function gets information about the Logical Drives present in a System
  4. ' Parameter : Computer IP ['.' for local computer]
  5. ' Return : strOut (String in [C: 10 GB free of 100 GB] [D: 10 GB free of 100 GB])
  6. ' Created By : Saqib Mujtaba
  7. ' Created On : 27-Sept-2012
  8. '-----------------------------------------------------------------------------------------------------------------------------------
  9. Function DiskUse(strComputer)
  10. On Error Resume Next
  11. Dim objDiskUse,objDisk,strOut
  12. strOut=""
  13. Err.Clear
  14. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  15. If Err=0 Then
  16. Set objDiskUse = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
  17. For Each objDisk in objDiskUse
  18. If objDisk.DriveType = 3 Then
  19. strOut = strOut & "[" & objDisk.DeviceID & " " & Round(objDisk.FreeSpace/1073741824,2) & " GB free of " & Round(objDisk.Size /1073741824,2) & " GB] " '& vbNewFile
  20. End If
  21. Next
  22.  
  23. DiskUse = strOut
  24. Else
  25. DiskUse ="WMI Connection Failed,WMI Connection Failed"
  26. End If
  27. Set objDiskUse = Nothing
  28. Set objWMIService = Nothing
  29. End Function

Report this snippet  

You need to login to post a comment.