public static void CopyTo(this FileInfo file, string computerName, string userName, string password, string remotePath = null) { using (RunAsContext runasContext = RunAs.Impersonate(userName, password)) { CopyTo(file, computerName, remotePath); } }
public static void UndoImpersonate(RunAsContext contextWrapper) { if (contextWrapper != null && contextWrapper.Context != null) { contextWrapper.Context.Undo(); } if (contextWrapper.TokenHandle != IntPtr.Zero) { CloseHandle(contextWrapper.TokenHandle); } }