Help with WMI Logical Disks Space.

  • Thread starter Thread starter teejayem
  • Start date Start date
T

teejayem

Hi.
Hopefully somebody out there will be able to help me!

I am using VB.Net and I am trying to find out logical disk
information.

I would like to be able to find the drive letters of any logical
disks, the size of each partition and how much free space is available
on the partition.

I have used the following code to list automatic services using WMI

Public Function GetAutoServices(ByVal Server As String) As
Collection
Dim colServices
Dim objService As Object
Dim colTemp As New Collection

Try
colServices = GetObject("winmgmts:
{impersonationLevel=impersonate}!\\" _
& Server & "\root\cimv2").ExecQuery("Select * from
Win32_Service")

For Each objService In colServices
If objService.StartMode = "Auto" Then
colTemp.Add(New Service(objService.DisplayName,
objService.State))
End If
Next

Return colTemp
Catch ex As Exception
MessageBox.Show(ex.Message)
Return colTemp
End Try
End Function

is it possible to find out the info i want using this method?
 
TeeJayEm,

Start a new console app

Add references to:

System.Management
System.Windows.Forms

Imports:

Imports System.Management
Imports System.Windows.Forms

Module Module1

Sub Main()
Try
Dim searcher As New
ManagementObjectSearcher("root\CIMV2","SELECT * FROM Win32_LogicalDisk")

For Each queryObj As ManagementObject In searcher.Get()

Console.WriteLine("-----------------------------------------")
Console.WriteLine("DeviceID: {0}", queryObj("DeviceID"))
Console.WriteLine("VolumeName: {0}", queryObj("VolumeName"))
Console.WriteLine("VolumeSerialNumber: {0}",
queryObj("VolumeSerialNumber"))
Console.WriteLine("FileSystem: {0}", queryObj("FileSystem"))
Console.WriteLine("DriveType: {0}", queryObj("DriveType"))
Console.WriteLine("Size: {0}", queryObj("Size"))
Console.WriteLine("FreeSpace: {0}", queryObj("FreeSpace"))
Next
Console.ReadLine()
Catch mex As ManagementException
MessageBox.Show("An error occurred: " & mex.Message)
End Try
End Sub

End Module

I hope this helps,
 
Back
Top