- Module Reseau
- Private Declare Sub MessageBeep Lib "User32" (ByVal N As Integer)
- Private strCritere As String = Nothing
-
- Sub callBeepDll(ByVal n As Integer)
- Call MessageBeep(n)
- End Sub
-
- ''' <summary>
- ''' Retourne une liste des ordinateurs sur le reseau
- ''' </summary>
- ''' <returns>List(Of String)</returns>
- ''' <remarks></remarks>
- Public Function ListeOrdiReseau() As List(Of String)
- Dim Proc As Process = New Process()
- Proc.StartInfo.FileName = "net.exe"
- Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
- Proc.StartInfo.Arguments = "view"
- Proc.StartInfo.UseShellExecute = False
- Proc.StartInfo.RedirectStandardOutput = True
- Proc.StartInfo.StandardOutputEncoding = System.Text.Encoding.Default
- Proc.Start()
-
- Dim CurrentCoding As System.Text.Encoding = Proc.StandardOutput.CurrentEncoding
- Dim st As New IO.StreamReader(Proc.StandardOutput.BaseStream)
- Dim output As String = st.ReadToEnd
- Proc.WaitForExit()
-
- Dim strOut As New List(Of String)
- strOut.AddRange(output.Split(vbCrLf))
- Dim outStr As String = Nothing
- For Each myServ As String In strOut
- If myServ.StartsWith(ControlChars.Lf & "\\") Then
- myServ = Replace(Trim(myServ), ControlChars.Lf, "").Trim
- If myServ.IndexOf(" ") > 0 Then
- outStr &= Strings.Left(myServ, myServ.LastIndexOf(" ")).Trim
- If outStr.IndexOf(" ") > 0 Then 'Un 2ème passage si comprend une désignation
- outStr = Strings.Left(outStr, outStr.LastIndexOf(" ")).Trim
- End If
- ElseIf myServ.IndexOf("\\") <> -1 Then
- outStr &= Strings.Left(myServ, myServ.LastIndexOf("") + 1).Trim
- Else
- If Not IsNothing(outStr) Then
- If outStr.IndexOf(" ") > 0 Then
- outStr = Strings.Left(outStr, outStr.LastIndexOf(" ")).Trim
- Else
- outStr &= myServ
- End If
- End If
-
- End If
- End If
- Next
- strOut.RemoveRange(0, strOut.Count)
- If Not IsNothing(outStr) Then strOut.AddRange(outStr.Split("\\"))
- '********** *****************************************************
- 'Permet de chercher un critere en le passant à la function cherche si ca correspond il l'enleve du tableau
- strCritere = ""
- Dim match As New System.Predicate(Of String)(AddressOf Cherche)
- strOut.RemoveAll(match)
- '****************************************************************
- strOut.TrimExcess()
- callBeepDll(-1)
- Return strOut
- End Function
-
- Private Function Cherche(ByVal p As String) As Boolean
- If p = strCritere Then
- Return True
- Else
- Return False
- End If
- End Function
- End Module
Module Reseau
Private Declare Sub MessageBeep Lib "User32" (ByVal N As Integer)
Private strCritere As String = Nothing
Sub callBeepDll(ByVal n As Integer)
Call MessageBeep(n)
End Sub
''' <summary>
''' Retourne une liste des ordinateurs sur le reseau
''' </summary>
''' <returns>List(Of String)</returns>
''' <remarks></remarks>
Public Function ListeOrdiReseau() As List(Of String)
Dim Proc As Process = New Process()
Proc.StartInfo.FileName = "net.exe"
Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
Proc.StartInfo.Arguments = "view"
Proc.StartInfo.UseShellExecute = False
Proc.StartInfo.RedirectStandardOutput = True
Proc.StartInfo.StandardOutputEncoding = System.Text.Encoding.Default
Proc.Start()
Dim CurrentCoding As System.Text.Encoding = Proc.StandardOutput.CurrentEncoding
Dim st As New IO.StreamReader(Proc.StandardOutput.BaseStream)
Dim output As String = st.ReadToEnd
Proc.WaitForExit()
Dim strOut As New List(Of String)
strOut.AddRange(output.Split(vbCrLf))
Dim outStr As String = Nothing
For Each myServ As String In strOut
If myServ.StartsWith(ControlChars.Lf & "\\") Then
myServ = Replace(Trim(myServ), ControlChars.Lf, "").Trim
If myServ.IndexOf(" ") > 0 Then
outStr &= Strings.Left(myServ, myServ.LastIndexOf(" ")).Trim
If outStr.IndexOf(" ") > 0 Then 'Un 2ème passage si comprend une désignation
outStr = Strings.Left(outStr, outStr.LastIndexOf(" ")).Trim
End If
ElseIf myServ.IndexOf("\\") <> -1 Then
outStr &= Strings.Left(myServ, myServ.LastIndexOf("") + 1).Trim
Else
If Not IsNothing(outStr) Then
If outStr.IndexOf(" ") > 0 Then
outStr = Strings.Left(outStr, outStr.LastIndexOf(" ")).Trim
Else
outStr &= myServ
End If
End If
End If
End If
Next
strOut.RemoveRange(0, strOut.Count)
If Not IsNothing(outStr) Then strOut.AddRange(outStr.Split("\\"))
'********** *****************************************************
'Permet de chercher un critere en le passant à la function cherche si ca correspond il l'enleve du tableau
strCritere = ""
Dim match As New System.Predicate(Of String)(AddressOf Cherche)
strOut.RemoveAll(match)
'****************************************************************
strOut.TrimExcess()
callBeepDll(-1)
Return strOut
End Function
Private Function Cherche(ByVal p As String) As Boolean
If p = strCritere Then
Return True
Else
Return False
End If
End Function
End Module