A Confused Programmer's Blog

This blog is dedicated to C# programming that I happen to do for living – with accent on curious cases and with sincere intent to make the world a better place as a result

NetJoinDomain failed with code 2 (File Not Found)

Many times when we are using PInvoke, the return value of the function specifying the error code might return some generic error that will leave the programmer scratching his head. We cannot demand from DLL producers to return meaningful error for each possible case and what happened today was just one example of this happening. I hope that my sad example will prevent critical sanity loss to someone who encounters similar problem.

In order to implement domain management, we are using netapi32 functions:

[DllImport(“netapi32.dll”, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint NetJoinDomain(string server, string domain, string accountOU, string account, string password, uint joinOptions);

And the call to this function will look somewhat like that:

Win32Imports.NetJoinDomain(null, “domain.local”, “OU=MyUnit,DC=domain,DC=local” @”domain.local\administrator”, “password”, 0x23);

The code was running smoothly at the production environment for a while, until for some obscure reason NetJoinDomain started returning “File Not Found” error. I will not get into all details of my investigation, but the bottom line is that apparently the OU that I specified in the call was erased at the domain controller – and this is the “file” that wasn’t found. Reinstating the required OU helped the application return being happy and hitting the man responsible for OU deletion with the big hammer helped me return being happy.

Hopefully, this story will help someone who runs into this error code when joining the domain.

Comments are closed.

Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Getting rid of Error

Since I upgraded my Windows 8 to Windows 10, I ...

Bypassing EULA step

We are working on automated testing of virtual appliance. This appliance ...

How I got rid of "Ac

OVF is a VMware virtual appliance format which allows you ...

My use-case of Perfo

In my blog I am set on a mission to ...

Connection to VIM AP

I rarely post about the issues I am experiencing in ...

Twitter updates

RSS not configured