I’m trying to get the PDC name for a domain on my network using the following code. It works fine within the VB IDE, but the moment I compile it and run it as an executable, it errors out with either

NERR_DCNotFound(2453): Could not find domain controller for this domain


ERROR_BAD_NETPATH(53): The network path was not found

Any idea what’s going wrong?

Here’s my code:

Private Declare Function NetGetDCName Lib "NETAPI32.DLL" _   (ServerName As Byte, DomainName As Byte, DCName As Long) As LongPrivate Declare Function lstrcpyW Lib _"kernel32.dll" (bRet As Byte, ByVal _lPtr As Long) As LongPrivate Declare Function NetApiBufferFree Lib _"Netapi32" (ByVal pBuffer As Long) As LongPublic Function GetPrimaryDCName(ByVal DName As String) As StringDim DCName As String, DCNPtr As LongDim DNArray() As Byte, DCNArray(100) As ByteDim result As LongDNArray = DName & vbNullCharresult = NetGetDCName(0&, DNArray(0), DCNPtr)If result <> 0 Then  Err.Raise vbObjectError + 4000, "CNetworkInfo", result  Exit FunctionEnd If lstrcpyW DCNArray(0), DCNPtrresult = NetApiBufferFree(DCNPtr)DCName = DCNArray() GetPrimaryDCName = Left(DCName, InStr(DCName, Chr(0)) - 1)End Function

That is very odd. I could not get your code to fail on a W2K machine, but it did fail as an executable under NT 4.0. I solved the problem by changing the declare as follows:

Private Declare Function NetGetDCName _   Lib "NETAPI32.DLL" _   (ServerName As Any, _    DomainName As Any, _    ppBuffer As Long) As Long

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several