UNCAccessWithCredentials NetUseAdd method returns 87 error in .NET
Know the following solution when you are getting 87 error from NetUseAdd() method of UNCAccessWithCredentials class when connecting to remote device or computer:
Using UNCAccessWithCredentials class, it helps to connect remote device or computer. NetUseAdd() accepts parameters like PathToRemoteDevice, DomainName, UserName & Password. If you have not specified the path of RemoteDevice and DomainName correctly, then it will throw 87 error. Following is the correct example of Remote Computer Path:
Valid path: string ConnectPath =@”\\computername.domainname.com\home\sub-foldername”;
Later it automatically converts it to: "\\\\computername.domainname.com\\home\\sub-foldername"
Also make sure you have removed the backslash from the end of the ConnectPath.
If you have specified the RemoteDevice path & Domain name path correctly, then you can check by putting the debugger at NetUseAdd() method and you can check for UserName, Password are all other parameters and confirm values of all these parameters are correct.
If you are getting 1219 error from NetUseAdd() method, then refer following article: http://www.techtutorhub.com/article/UNCAccessWithCredentials-NetUseAdd-method-returns-1219-error-in-dot-NET-C-sharp/55