使用网络凭据通过 Process.Start(path) 访问网络共享
我正在使用 this Impersonator 类来模拟域帐户来访问网络共享,例如所以:
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 路径?
I am using this Impersonator class to impersonate a domain account to access a network share like so:
using(new Impersonartor(username, domain, password))
{
//Code Here
}
Copying the file from the network share works okay:
using(new Impersonartor(username, domain, password))
{
CopyAll(uncPath, localPath)
}
However, using Process.Start to view the UNC share in Explorer throws a "Logon failure: unknown user name or bad password":
using(new Impersonartor(username, domain, password))
{
Process.Start(uncPath)
}
Suspecting that the Impersonator class is at fault, I tried manually supplying the credentials to ProcessStartInfo like so:
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);
Still no joy. Note that I'm sure that my netCred (NetworkCredential) is correct as I've used to make prior connections to authenticated resources.
So, how do I view a UNC path in Explorer using a network credential?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我今天遇到了同样的问题,这对我有用:
I had the same problem today and here is what worked for me:
不要将 uncPath 传递给 Process.Start,而是尝试在 Process.Start 中启动“explorer”并将 uncPath 作为 ProcessStartInfo 的
传递code>Arguments
属性。Instead of passing the uncPath to the
Process.Start
, try starting "explorer" inProcess.Start
and pass the uncPath asProcessStartInfo
'sArguments
property.