Public Shared Function getDrives(ByVal sName As String) As DataTable
Dim options As New ConnectionOptions
options.Impersonation = ImpersonationLevel.Impersonate
options.Authentication = AuthenticationLevel.Packet
Dim mScope As New ManagementScope("\\" & sName & "\root\PG_Internal", options)
' The documentation notes that this namespace is installed with IBM director also
'Dim mScope As New ManagementScope("\\" & sName & "\root\PG_InterOp", options)
' And this one
'Dim mScope As New ManagementScope("\\" & sName & "\root\IBMSD", options)
' This is the class that the documentation contains the information I want
Dim mQuery As New SelectQuery("SELECT * FROM IBMPSG_RAIDDiskDrive")
Dim mSearcher As New ManagementObjectSearcher(mScope, mQuery)
' build the datatable
Dim mPropertiesTable As New DataTable
Dim mPropertiesRow As DataRow
Dim dcDriveLetter As New DataColumn("Letter", GetType(String)) mPropertiesTable.Columns.Add(dcDriveLetter)
Try
mScope.Connect()
' Check the connection
If mScope.IsConnected Then
' traverse through each record given
For Each driveObj As ManagementObject In mSearcher.Get()
' Create a new row for the datatable
mPropertiesRow = mPropertiesTable.NewRow
' Traverse through the properties found...
For Each driveProperty In driveObj.Properties
' Create the header row
If mPropertiesTable.Columns.Count <> driveObj.Properties.Count + 1 Then
Dim dcDriveProperty As New DataColumn(driveProperty.Name, GetType(String))
mPropertiesTable.Columns.Add(dcDriveProperty)
End If
' Get the property value
mPropertiesRow(driveProperty.Name) = driveProperty.Value
Next
' Add the row
mPropertiesTable.Rows.Add(mPropertiesRow)
Next
End If
' Return the datatable
Return mPropertiesTable
Catch ex As Exception
' Return a datatable showing the exception
mPropertiesRow = mPropertiesTable.NewRow()
mPropertiesRow("Letter") = ex.Message.ToString & "[" & System.Security.Principal.WindowsIdentity.GetCurrent().Name & "]"
mPropertiesTable.Rows.Add(mPropertiesRow)
Return mPropertiesTable
End Try
End Function
|