Accessing network share via Process.Start(path) using network credential
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?
我今天遇到了同样的问题,下面是对我有用的问题:
private void OpenNetworkPath(string uncPath)
{
System.Diagnostics.Process.Start("explorer.exe", uncPath);
}
不要将uncPath传递给Process.Start
,而是尝试在Process.Start
启动“explorer”,并将uncPath作为ProcessStartInfo
的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);
链接地址: http://www.djcxy.com/p/44166.html