[Visual Basic] Creare una funzione per ottenere le informazioni sulla memoria del disco logico

Nel tutorial di oggi imparerete come creare una funzione che permette di ottenere le informazioni sulla memoria del disco logico con Visual Basic.

 
'-----------------------------------------------------------------------------------------------------------------------------------
' Function    : DiskUse(string)
' Description : This Function gets information about the Logical Drives present in a System
' Parameter   : Computer IP ['.' for local computer]
' Return      : strOut (String in [C: 10 GB free of 100 GB] [D: 10 GB free of 100 GB])
' Created By  : Saqib Mujtaba
' Created On  : 27-Sept-2012
'-----------------------------------------------------------------------------------------------------------------------------------
Function DiskUse(strComputer)
On Error Resume Next
	Dim objDiskUse,objDisk,strOut
	strOut=""
	Err.Clear
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
If Err=0 Then
	Set objDiskUse = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
	For Each objDisk in objDiskUse
		If objDisk.DriveType = 3 Then
			strOut = strOut & "[" & objDisk.DeviceID & " " & Round(objDisk.FreeSpace/1073741824,2) & " GB free of " & Round(objDisk.Size /1073741824,2) & " GB] " '& vbNewFile
		End If
	Next 
 
	DiskUse = strOut
Else
		DiskUse ="WMI Connection Failed,WMI Connection Failed"
	End If
	Set objDiskUse = Nothing
	Set objWMIService = Nothing
End Function