Hi everyone,
I am trying to populate my datagrid (name: GridLocalDisk) with data from a WMI query.
I have three columns within my data grid (Drive, diskSize, and Remaining)
How would I populate each "DeviceID" into the "Drive" column?
How would I populate each "Size" into the "diskSize" column?
How would I populate each "FreeSpace" into the "Remaining" column?
Below is my WMI code. I currently have the data outputting to a listbox (ListBox3).
Any help would be greatly appreciated.
Code:Function SetBytes(ByVal Bytes) As String SetBytes = Format(Bytes / 1024 / 1024 / 1024, "#0.00") & " GB" End Function Private Sub btnQueryMachine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQueryMachine.Click Dim manScope As ManagementScope Dim manPath As ManagementPath Dim manClass As ManagementClass Dim manObj As ManagementObject Dim manObjCol As ManagementObjectCollection Dim output As String = String.Empty Dim RemoteMachineName As String RemoteMachineName = "COMPUTERNAME" Try manPath = New ManagementPath("\\" & RemoteMachineName & "\root\CIMV2:Win32_LogicalDisk") manScope = New ManagementScope(manPath) 'Since it is a remote system, you must provide proper credentials to access it 'manScope.Options.Username = "yourDomainName\administrator" 'manScope.Options.Password = "yourPassword" manClass = New ManagementClass(manScope, manPath, Nothing) manObjCol = manClass.GetInstances() For Each manObj In manObjCol If (manObj("Description").ToString) = "Local Fixed Disk" Then ListBox3.Items.Add(manObj("DeviceID").ToString) ListBox3.Items.Add(SetBytes(manObj("Size").ToString)) ListBox3.Items.Add(SetBytes(manObj("FreeSpace").ToString)) End If Next ' MessageBox.Show(output) Catch ex As Exception ' MessageBox.Show(ex.Message) Finally manPath = Nothing manScope = Nothing manClass = Nothing manObjCol = Nothing End Try End Sub




Reply With Quote