使用网络凭据通过 Process.Start(path) 访问网络共享

发布于 2024-10-01 03:30:53 字数 1194 浏览 7 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幼儿园老大 2024-10-08 03:30:53

我今天遇到了同样的问题,这对我有用:

private void OpenNetworkPath(string uncPath)
{
   System.Diagnostics.Process.Start("explorer.exe", uncPath);
}

I had the same problem today and here is what worked for me:

private void OpenNetworkPath(string uncPath)
{
   System.Diagnostics.Process.Start("explorer.exe", uncPath);
}
凉栀 2024-10-08 03:30:53

不要将 uncPath 传递给 Process.Start,而是尝试在 Process.Start 中启动“explorer”并将 uncPath 作为 ProcessStartInfo 的 传递code>Arguments 属性。

System.Diagnostics.ProcessStartInfo viewDir = new System.Diagnostics.ProcessStartInfo("explorer.exe");
viewDir.UseShellExecute = false;
viewDir.Domain = netCred.Domain;
viewDir.UserName = netCred.UserName;
viewDir.Password = ConvertToSecureString(netCred.Password);
viewDir.Arguments = uncPath;
System.Diagnostics.Process.Start(viewDir);

Instead of passing the uncPath to the Process.Start, try starting "explorer" in Process.Start and pass the uncPath as ProcessStartInfo's Arguments property.

System.Diagnostics.ProcessStartInfo viewDir = new System.Diagnostics.ProcessStartInfo("explorer.exe");
viewDir.UseShellExecute = false;
viewDir.Domain = netCred.Domain;
viewDir.UserName = netCred.UserName;
viewDir.Password = ConvertToSecureString(netCred.Password);
viewDir.Arguments = uncPath;
System.Diagnostics.Process.Start(viewDir);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文