我在用this http://www.codeproject.com/KB/cs/zetaimpersonator.aspxImpersonator 类模拟域帐户来访问网络共享,如下所示:
using(new Impersonartor(username, domain, password))
{
//Code Here
}
从网络共享复制文件可以正常工作:
using(new Impersonartor(username, domain, password))
{
CopyAll(uncPath, localPath)
}
但是,使用 Process.Start 在资源管理器中查看 UNC 共享会引发“登录失败:未知的用户名或错误密码”:
using(new Impersonartor(username, domain, password))
{
Process.Start(uncPath)
}
怀疑 Impersonator 类有问题,我尝试手动向 ProcessStartInfo 提供凭据,如下所示:
System.Diagnostics.ProcessStartInfo viewDir = new System.Diagnostics.ProcessStartInfo(uncPath);
viewDir.UseShellExecute = false;
viewDir.Domain = netCred.Domain;
viewDir.UserName = netCred.UserName;
viewDir.Password = ConvertToSecureString(netCred.Password);
System.Diagnostics.Process.Start(viewDir);
还是没有喜悦。请注意,我确信我的 netCred (NetworkCredential) 是正确的,因为我曾经用于预先连接到经过身份验证的资源。
那么,如何使用网络凭据在资源管理器中查看 UNC 路径?