Query with WMI and using the CIM_DataFile Private Function GetQueueSize(ByVal strServerName As String, ByVal strPath As String, ByVal strUID As String, ByVal strPWD As String) As Integer
Dim options As New ConnectionOptions() Dim retValue As New System.Text.StringBuilder options.Username = strUID options.Password = strPWD Dim scope As ManagementScope If strServerName = “LocalPCName” Then scope = New ManagementScope(“\” & strServerName & “rootcimv2”) Else scope = New ManagementScope(“\” & strServerName & “rootcimv2”, options) End If
‘Dim selectQuery As New SelectQuery(“SELECT * FROM CIM_DataFile
Where PATH = ‘\inetpub\mailroot\queue\’ and Extension=’eml'”) ‘Dim selectQuery As New SelectQuery(“ASSOCIATORS OF {Win32_Directory.Name='” & strPath & “‘} Where ResultClass = CIM_DataFile”) Dim oSelectQuery As New SelectQuery(“SELECT * FROM CIM_DataFile where path='” & strPath & “‘ and Extension=’eml'”) Dim searcher As New ManagementObjectSearcher(scope, oSelectQuery)
Try scope.Connect() Catch f As Exception Console.Write(f.Message.ToString()) End Try
Console.WriteLine(“ServerName : ” & strServerName & ” strPath ” & strPath & ” Number of files: ” & searcher.Get().Count)
Return searcher.Get().Count() End Function
Query with WMI and using System.IO.DirectoryInfo class Sub GetDirectoryInfo(ByVal strServerName As String, ByVal path As String) ‘ Create a reference to the current directory. Dim di As New System.IO.DirectoryInfo(“\” & strServerName & path)
‘ Create an array representing the files in the current directory. Dim fi As System.IO.FileInfo() = di.GetFiles(“*.eml”)
‘ Print out the names of the files in the current directory. Dim x As Integer = UBound(fi)
‘writes out the # of files in the particular directory Console.writeline(x)
End Sub |