本文介绍了使用DataGrid VB.NET将用户添加到Active Directory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我需要使用DataGrid在Active Directory中添加用户.我在VBS中有一个脚本,可以完美地执行指定形式的脚本:
Hello,
I need add users in Active Directory using DataGrid. I have one script in VBS that function perfectly of specified form:
cont = 0
for cont = 0 to 4
intRow = 3
Set objExcel = CreateObject("Excel.Application")
strSheet = objFolder.self.path & "\users" & (myDEP(cont)) & site & ".xls"
Set objSpread = objExcel.Workbooks.Open(strSheet)
If objSpread Is Nothing Then
Wscript.Echo "ERROR: "
Wscript.Echo ""
WScript.Quit
End If
Set objAdd = GetObject("LDAP://ou=Users,ou=" & (myDEP(cont)) & ",ou=" & site & ",ou=PETRONIO,dc=petronio,dc=local")
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Trim(objExcel.Cells(intRow, 1).Value)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strPWD = Trim(objExcel.Cells(intRow, 5).Value)
Set objUser = objAdd.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strSam
objUser.givenName = strFirst
objUser.sn = strLast
objUser.userPrincipalName = strSam & "@petronio.local"
objUser.displayName = strFirst & " " & strLast
objUser.SetInfo
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo
intRow = intRow + 1
Loop
objExcel.Quit
Next
重要的部分是:
The important part is:
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Trim(objExcel.Cells(intRow, 1).Value)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strPWD = Trim(objExcel.Cells(intRow, 5).Value)
已经将数据加载到DataGrid.这部分将如何使用DataGrid?
最好的问候,
Joao Paulo
Already loaded data to the DataGrid. How would this part using the DataGrid?
Best Regards,
Joao Paulo
推荐答案
DataGridView1.Rows(a).Cells(b).Value.ToString.Trim = ""
这篇关于使用DataGrid VB.NET将用户添加到Active Directory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!