none
Execute mstsc from data in gridview RRS feed

  • Question

  • I'm new in the world of programming so I come to ask for some help!

    I try to put a button in my form whow execute mstsc.exe from data in the gridview. This gridview populate from AD

    This is the code for the grid:

        Imports System.DirectoryServices
    Public Class Form1
    Dim tblPeople As New DataTable("Server")
    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' instantiate a new DataSet object that   
        Dim dataSet As New DataSet()
        Dim col As DataColumn
        Dim row As DataRow
    
        ' Create Name column   
        col = New DataColumn("Nombre", System.Type.[GetType]("System.String"))
        col.DefaultValue = ""
        tblPeople.Columns.Add(col)
    
        ' Create DNS column 
        col = New DataColumn("DNS", System.Type.[GetType]("System.String"))
        col.DefaultValue = ""
        tblPeople.Columns.Add(col)
    
        'col = New DataColumn("Desc", System.Type.[GetType]("System.String"))
        ' Iterate over all the results in the resultset.   
    
        Dim objADAM As DirectoryEntry                   ' Binding object.
        Dim objSearchADAM As DirectorySearcher          ' Search object.
        Dim objSearchResults As SearchResultCollection  ' Results collection.
        Dim strPath As String                           ' Binding path.
    
        Dim i As Integer 'Used to cont the number of groups retrieved.
        i = 0
    
        ' Construct the binding string.        
        strPath = "LDAP://ou=xx,ou=xx,ou=xx,xx=cabal,xx=coop"
    
        'Try
        ' Get the AD LDS object.
        objADAM = New DirectoryEntry(strPath, "user", "password")
        objADAM.RefreshCache()
    
        ' Get search object, specify filter and scope,
        ' perform search.
        objSearchADAM = New DirectorySearcher(objADAM)
    
        objSearchADAM.PageSize = 1000
    
        objSearchADAM.Filter = "(&(objectCategory=Computer)(objectClass=computer))"
    
    
        objSearchADAM.SearchScope = SearchScope.Subtree
        objSearchResults = objSearchADAM.FindAll()
        'Dim result As New List(Of String)
        For Each result As SearchResult In objSearchResults
            row = tblPeople.NewRow()
            ' Getting values   
    
            ' Display Nombre   
    
            If result.Properties.Contains("Name") Then
                row("Nombre") = result.Properties("Name")(0).ToString()
            End If
    
            ' Display DNS   
            If result.Properties.Contains("DNSHostName") Then
                row("DNS") = result.Properties("DNSHostName")(0).ToString()
            End If
    
            If row("Nombre") <> "" Then
                tblPeople.Rows.Add(row)
            End If
    
        Next
    
        dataSet.Tables.Add(tblPeople)
    
        ' set the data source for the grid to the people table   
        DataGridView1.DataSource = dataSet.Tables("Server")
    End Sub
    If anyone has any recommendations about the code I am using, it is welcome! Thanks and sorry for my bad english!
    Friday, February 1, 2019 4:21 PM

Answers

All replies