Help with WMI Logical Disks Space.

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?
 
N

Newbie Coder

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top