Here is the gist of my code.
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
I built it into a neat Exe and scheduled it to run using Windows Task Scheduler.
0x80005000 that i get is for the line
But here is the kicker: When I run the task scheduler while logged in it runs flawlessly, but when I log out and let it run on it's own, it gives me the error on that line.
What I think is when I create the new
DirectoryEntry object I should use some authentication but I'm not sure how to do it without writing the password and username clearly. I want it to just use the credentials of the user specified by the task scheduler.
Hope I am clear enough with my question and that anyone will be both willing and able to help me with this.
p.s. the option to run whether user is logged on or not is checked. and the program does a lot of other things like writing to a log file and getting the info, it just refuses to move the objects when needed.
User contributions licensed under CC BY-SA 3.0