Click to See Complete Forum and Search --> : Issues With Using DirectoryEntry.Invoke()


Scott MacMaster
February 14th, 2008, 07:35 PM
While researching how to write a program to interface with Active Directory I read that Inoke() can only be called once per program execution. It seemed unlikely that was true so I coded my program to simply call Invoke() whenever I needed. Mostly for setting a password or adding a user to a group. It worked but I had stability issues. Mainly I would get MDA errors. Usually it was the one that says 'ContextSwitchDeadlock was detected'. I read that this is caused by a process not responding to window messages. Does Invoke() start up a thread that doesn't go away? Should I write code that kills this thread after Invoke() returns?

What I read suggested that I write a small program that simply calls Invoke() and returns. So I wrote a program that does that and I call it with this code


Dim info As ProcessStartInfo = New ProcessStartInfo
info.FileName = "D:\Custom Programs\ADCommandInvoker"
info.Arguments = "ADPath|""" + group.Path + """ ADCommand|Add" + " ADParameter|""" + deUser.Path + """"
info.CreateNoWindow = True
info.UseShellExecute = False

Dim invoker As Process = Process.Start(info)
invoker.WaitForExit()


My program does seem to run better like this. Can someone tell me if it is worth doing it like this? I read that MDA messages go away when the program is not run from the debugger. So I suspect I should just call Invoke().

The goal of this program is to take our list of active students make sure they all have an active directory account, disable accounts for students who are no longer active, create a network drive for eash student, verify their active directory settings are correct, and to verify their network drive permissions are correct.

Currently, this program takes 30-45 minutes to process about 3400 students. My helper program is called about once per student. If I can simply call Invoke() I suspect the processing time will drop a lot.

I want this to work as a job the runs nightly. Random error message or failures will make this impossible.

I know I have a lot of questions. Can someone at least answer most of them?


Thanks,
Scott

dglienna
February 14th, 2008, 07:53 PM
Have you seen this?
https://www.microsoft.com.nsatc.net/technet/scriptcenter/tools/admatic.mspx