3

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?

Ian
  • 5,625
  • 11
  • 57
  • 93

2 Answers2

3

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);
}
Random Developer
  • 1,334
  • 2
  • 12
  • 31
0

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);
  • Sorry, I forgot to mention that I've already tried that. Thanks! – Ian Nov 09 '10 at 09:52
  • Hi @Ian, I tried creating a very basic program to test out the code and it seems to load fine. I think the issue is related to your environment, can you give further more details about your OS / version / overall domain setup and if the network credentials is stored locally in the client OS vault? –  Nov 09 '10 at 10:11
  • Sure. Windows 7 Professional 32bit. Machine is not joined to the domain. The NetworkCredentials object is being populated during runtime. The netcred object is being used to connect to different network services such as TFS (Works fine). The credential is not stored in the OS vault. – Ian Nov 09 '10 at 10:37