The following code is available:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Principal; using System.IO; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string username = @"Abserv\r.ivanov"; // Нужно чтобы соединялось и через домен и без. string password = @"Blab"; string network_file_path = @"\\172.10.0.80\c$\test\test.txt"; string local_file_path = @"c:\test\test.txt"; AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); WindowsIdentity idnt = new WindowsIdentity(username, password); WindowsImpersonationContext context = idnt.Impersonate(); File.Copy(network_file_path, local_file_path, true); context.Undo(); } } } 

However, when executing this code, the error "The specified name is not correct" occurs:

Screenshot of console window with error text

What is the cause of this problem?

  • Please format the code. Your question is not readable. - Pavel Mayorov
  • The directory `c: \ test` exists? - kmv
  • Yes there is ((( - Ivan Nechkin
  • Something on the msdn example is much more complicated. - Qwertiy
  • 3
    I vote for closing this question, because it is set again under another user (who is also not registered). This user probably no longer exists , so this question should be closed, not the one. @IvanNechchkin, if this user still exists, and that question is not yours, write about it in the comment. - Qwertiy

1 answer 1

The second parameter, WindowsIdentity , is not a password. See an example

  • Not clear yet ( - Ivan Nechkin