Click here to Skip to main content
15,887,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports System.DirectoryServices
Imports System.Net
Public Class frmMain
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
     Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents txtcomputer As System.Windows.Forms.TextBox
    Friend WithEvents txtmessage As System.Windows.Forms.TextBox
    Friend WithEvents CmdSend As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents CmdPing As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents CmdSendAll As System.Windows.Forms.Button
    <system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmMain))
        Me.CmdSend = New System.Windows.Forms.Button()
        Me.TreeView1 = New System.Windows.Forms.TreeView()
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.txtcomputer = New System.Windows.Forms.TextBox()
        Me.txtmessage = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.CmdPing = New System.Windows.Forms.Button()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.CmdSendAll = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'CmdSend
        '
        Me.CmdSend.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CmdSend.Location = New System.Drawing.Point(463, 271)
        Me.CmdSend.Name = "CmdSend"
        Me.CmdSend.Size = New System.Drawing.Size(54, 32)
        Me.CmdSend.TabIndex = 0
        Me.CmdSend.Text = "&Send"
        '
        'TreeView1
        '
        Me.TreeView1.ImageList = Me.ImageList1
        Me.TreeView1.Location = New System.Drawing.Point(0, 48)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Size = New System.Drawing.Size(224, 248)
        Me.TreeView1.TabIndex = 1
        '
        'ImageList1
        '
        Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'txtcomputer
        '
        Me.txtcomputer.Name = "txtcomputer"
        Me.txtcomputer.Size = New System.Drawing.Size(224, 20)
        Me.txtcomputer.TabIndex = 2
        Me.txtcomputer.Text = ""
        '
        'txtmessage
        '
        Me.txtmessage.Location = New System.Drawing.Point(224, 176)
        Me.txtmessage.Multiline = True
        Me.txtmessage.Name = "txtmessage"
        Me.txtmessage.Size = New System.Drawing.Size(296, 88)
        Me.txtmessage.TabIndex = 3
        Me.txtmessage.Text = ""
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(224, 160)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(117, 15)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "Message To Send"
        '
        'CmdPing
        '
        Me.CmdPing.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CmdPing.Location = New System.Drawing.Point(313, 271)
        Me.CmdPing.Name = "CmdPing"
        Me.CmdPing.Size = New System.Drawing.Size(54, 32)
        Me.CmdPing.TabIndex = 5
        Me.CmdPing.Text = "&Ping"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(87, 24)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(136, 20)
        Me.TextBox1.TabIndex = 6
        Me.TextBox1.Text = ""
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(0, 24)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(81, 15)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "IP Address :"
        '
        'CmdSendAll
        '
        Me.CmdSendAll.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.CmdSendAll.Location = New System.Drawing.Point(367, 271)
        Me.CmdSendAll.Name = "CmdSendAll"
        Me.CmdSendAll.Size = New System.Drawing.Size(96, 32)
        Me.CmdSendAll.TabIndex = 8
        Me.CmdSendAll.Text = "&Send To All"
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(520, 309)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CmdSendAll, Me.Label2, Me.TextBox1, Me.CmdPing, Me.Label1, Me.txtmessage, Me.txtcomputer, Me.TreeView1, Me.CmdSend})
        Me.Name = "frmMain"
        Me.Text = "Lan Messanger"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim childEntry As DirectoryEntry
        Dim ParentEntry As New DirectoryEntry()
        Try
            ParentEntry.Path = "WinNT:"
            For Each childEntry In ParentEntry.Children
                Dim newNode As New TreeNode(childEntry.Name)
                Select Case childEntry.SchemaClassName
                    Case "Domain"
                        Dim ParentDomain As New TreeNode(childEntry.Name)
                        TreeView1.Nodes.AddRange(New TreeNode() {ParentDomain})

                        Dim SubChildEntry As DirectoryEntry
                        Dim SubParentEntry As New DirectoryEntry()
                        SubParentEntry.Path = "WinNT://" & childEntry.Name
                        For Each SubChildEntry In SubParentEntry.Children
                            Dim newNode1 As New TreeNode(SubChildEntry.Name)
                            Select Case SubChildEntry.SchemaClassName
                                Case "Computer"
                                    ParentDomain.Nodes.Add(newNode1)
                            End Select
                        Next
                End Select
            Next
        Catch Excep As Exception
            MsgBox("Error While Reading Directories")
        Finally
            ParentEntry = Nothing
        End Try

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSend.Click
        If txtcomputer.Text <> "" And txtmessage.Text <> "" Then
            Shell("net send " & txtcomputer.Text & " " & txtmessage.Text)
            txtmessage.Text = ""
            txtmessage.Focus()
        End If
    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        txtcomputer.Text = TreeView1.SelectedNode.Text
        TextBox1.Text = GetIPAddress(txtcomputer.Text)
    End Sub

    Function GetIPAddress(ByVal CompName As String) As String
        Dim oAddr As System.Net.IPAddress
        Dim sAddr As String
        Try
            With System.Net.Dns.GetHostByName(CompName)
                oAddr = New System.Net.IPAddress(.AddressList(0).Address)
                sAddr = oAddr.ToString
            End With
            GetIPAddress = sAddr
        Catch Excep As Exception
            MsgBox(Excep.Message, MsgBoxStyle.OKOnly, "Lan Messenger")
        Finally

        End Try
    End Function

    Private Sub CmdPing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdPing.Click
        Shell("PING " & TextBox1.Text)
    End Sub

    Private Sub CmdSendAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSendAll.Click
        Shell("net send ALL " & txtmessage.Text)
    End Sub
End Class
Posted
Updated 17-Mar-12 4:48am
v2
Comments
André Kraak 17-Mar-12 10:48am    
Edited question:
Added pre tags

1 solution

Yoiu may have to do it method by method, but have a try with this: http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
 
Share this answer
 
Comments
Uday P.Singh 17-Mar-12 11:00am    
5!
cool_kp 18-Mar-12 1:23am    
thanks I got C# code. it's very useful.
OriginalGriff 18-Mar-12 4:25am    
Isn't it though! :laugh:
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900