我是编程领域的新手,所以我来寻求帮助!
我尝试在表单中放置一个按钮,该按钮将从gridview中的数据执行mstsc.exe。此gridview从AD填充
这是网格的代码:
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
如果有人对我使用的代码有任何建议,欢迎您! 谢谢! 谢谢! 谢谢!