DsGetDcName Timeout

Today I was looking for the source of frequent delays when setting permissions from my new application SetACL Studio. I sprinkled the code with timestamped debug statements like these…

System.Diagnostics.Debug.WriteLine(DateTime.Now + " - 1");
// Do something
System.Diagnostics.Debug.WriteLine(DateTime.Now + " - 2");

…and found that the delays always had a duration of seven seconds. Wait - “inexplicable” delays of constant length - that smells of timeouts!

And indeed, by stepping into the underlying unmanaged code it was pretty easy to identify the call causing the timeouts:

if (DsGetDcName (NULL, sDomainName, NULL, NULL, 0, &pdcInfo) == ERROR_SUCCESS)

This happened if sDomainName was equal to the local computer name, i.e. when looking for a (nonexistent) domain with the name of my computer.

I fixed that line by adding a check if sDomainName is different from the local computer name:

CString sComputername;
sComputername.GetEnvironmentVariable(L"computername");
if (sComputername.CompareNoCase(sDomainName) != 0)
{
   // Call DsGetDcName here
}

Comments

Related Posts

How to Enable Drag and Drop for an Elevated MFC Application on Windows

Finding good information on how to enable drag and drop for MFC applications is hard enough (why?). But just when you think you should have it working, you hit a very solid wall: UIPI (User Interface Privilege Isolation, a variant of UAC, User Account Control). Because of “security” reasons, UIPI disables drag and drop from medium integrity processes (Explorer) to high integrity (aka elevated) processes by filtering out most window messages, including those required for drag and drop. In essence drag and drop from Explorer to your elevated application does not work.
Software development