这是我的代码的要点。
Public Sub GetADUserList(ByVal ADLoc As String, ByVal vLock As Boolean, ByVal vDays As Integer, ByVal move As Boolean, ByVal vMoveFolder As String, ByVal server As String, resultFile As String)
Dim entry As New DirectoryServices.DirectoryEntry("LDAP://" & ADLoc)
Dim mySearcher As New DirectoryServices.DirectorySearcher(entry)
mySearcher.PageSize = 1000
mySearcher.Filter = ("(objectClass=user)")
For Each resEnt As DirectoryServices.SearchResult In mySearcher.FindAll()
HandleUser(resEnt, vLock, move, vMoveFolder, resultFile, vDays)
Next
End Sub
Private Sub HandleUser(resEnt As DirectoryServices.SearchResult, vlock As Boolean, move As Boolean, moveFold As String, resultFile As String, vdays As Integer)
Dim de As DirectoryServices.DirectoryEntry = resEnt.GetDirectoryEntry()
''' a lot of IF Functions that check the properties and make sure I want to work on the current object
''' also there are debugging functions.. logging functions etc.. i ommited them because they all work
de.MoveTo(New DirectoryServices.DirectoryEntry("LDAP://" & logon_Server & "/" & moveFold))
End Sub
我将它构建成一个整洁的Exe并安排它使用 Windows任务计划程序运行。
我得到的错误0x80005000
适用于行de.MoveTo
。
但是这里是踢球者:当我在登录时运行任务调度程序时它运行完美,但是当我退出并让它在它自己运行时,它会在该行上给出错误。
我认为当我创建新的DirectoryEntry
对象时,我应该使用一些身份验证,但我不知道如何在不写清楚密码和用户名的情况下执行此操作。我希望它只使用任务调度程序指定的用户凭据。
希望我对自己的问题很清楚,任何人都愿意并且能够帮助我。
问候,瓦西里。
P.S。检查用户是否登录的选项。 并且该程序执行许多其他操作,例如写入日志文件和获取信息,它只是在需要时拒绝移动对象。