Hi Stephen,
I wrote a the routines to iterate through folders on a remote computer in
C#. I took the code and converted it VB.NET. It works. I took the exact
same syntax and plugged it into my new VB.NET class and the statement works.
I am not sure what is different. I am posting the code to my VB.NET class
for others to use as a sample since I have found very little documentation on
the .NET side.
Imports System.Management
Public Class FileSystem
Private moScope As ManagementScope
Public Sub New(ByVal sComputerName As String)
moScope = New ManagementScope("\\" + sComputerName + "\root\cimv2")
End Sub
Public Function RetrieveFixedDrives() As String()
Dim oSelectQuery As SelectQuery
Dim iDriveType As Integer
Dim sDrives() As String
Dim oSearcher As ManagementObjectSearcher
Dim oMgmtObjColl As ManagementObjectCollection
Dim oDisk As ManagementObject
Dim iCount As Integer
oSelectQuery = New SelectQuery("win32_logicalDisk")
oSearcher = New ManagementObjectSearcher(moScope, oSelectQuery)
oMgmtObjColl = oSearcher.Get
ReDim sDrives(oMgmtObjColl.Count)
iCount = 0
For Each oDisk In oMgmtObjColl
iDriveType =
Integer.Parse(oDisk.Properties("DriveType").Value.ToString)
If iDriveType = 3 Then
sDrives(iCount) =
oDisk.Properties("DeviceID").Value.ToString()
iCount += 1
End If
Next oDisk
ReDim Preserve sDrives(iCount - 1)
Return sDrives
End Function
Public Function RetrieveFolders(ByVal sParentFolder As String) As String()
Dim sFolders() As String
Dim sReturnFolders() As String
Dim iCount As Integer
Dim oMgmtObjColl As ManagementObjectCollection
Dim oFolder As ManagementObject
Dim bHidden As Boolean
Dim oSelectQuery As New WqlObjectQuery("ASSOCIATORS OF
{Win32_Directory.Name='" + sParentFolder + "'} WHERE AssocClass =
Win32_Subdirectory ResultRole = PartComponent")
Dim oSearcher As New ManagementObjectSearcher(moScope, oSelectQuery)
oMgmtObjColl = oSearcher.Get
ReDim sFolders(oMgmtObjColl.Count)
iCount = 0
For Each oFolder In oSearcher.Get()
bHidden = Convert.ToBoolean(oFolder.Properties("Hidden").Value)
If bHidden = False Then
sFolders(iCount) =
oFolder.Properties("FileName").Value.ToString()
iCount += 1
End If
Next
ReDim Preserve sFolders(iCount - 1)
Return sFolders
End Function
End Class