Решение с использованием "net view \\ servername "
Я знаю, что не очень желательно использовать консольную команду и выполнять некоторые строковые гимнастические операции на выходе, но с другойэто работает, и не очень желательно, по крайней мере для меня, возиться с настройками DCOM по умолчанию, чтобы заставить работать WMI (по крайней мере, на Win7s).
Был протестирован наКлиенты Win7 и XP, а также серверы MS и Linux.
Function GetShares(ServerName As String) As List(Of String)
Try
Dim P As New Process
Dim Read As Boolean = False
Dim Str As String
Dim Shares As New List(Of String)
With P.StartInfo
.FileName = "net"
.Arguments = "view " & ServerName
.RedirectStandardOutput = True
.RedirectStandardError = True
.CreateNoWindow = True
.UseShellExecute = False
End With
P.Start()
P.WaitForExit()
If P.ExitCode <> 0 Then
MsgBox(P.StandardError.ReadToEnd, MsgBoxStyle.OkOnly, "Error")
Else
Do Until P.StandardOutput.EndOfStream = True
If Read = True Then
Str = P.StandardOutput.ReadLine
If Str = "The command completed successfully." Then Exit Do
Str = Strings.RTrim(Str) 'Removes any trailing spaces
Str = Strings.Mid(Str, 1, Strings.InStrRev(Str, " ")) 'remove Type
Str = Strings.RTrim(Str) ''Removes any trailing spaces
Shares.Add(Str)
Else
If Strings.Left(P.StandardOutput.ReadLine, 10) = "----------" Then Read = True
End If
Loop
End If
Return Shares
Catch ex As Exception
MsgBox("Error in """ & System.Reflection.MethodInfo.GetCurrentMethod.Name & """: " & vbCr & ex.Message, MsgBoxStyle.OkOnly, "Runtime error")
Debug.Print("--------------------------" & vbCr & "Error: " & ex.Message & vbCr & ex.StackTrace)
Return Nothing
End Try
End Function