0

I have a .NET windows application I am writing in which I want to run "explorer.exe" to open a file. Basically, I have this program that shows users files (in a grid) that is in a folder on the network in which they do not have access to. So basically I want them to be able to view certain files (like Doc(x), PDF, JPG, etc). When they click on the file in the grid, I want it to launch the appropriate application for the extension of the selected file. When using this as myself it was working using:

Process.Start("explorer.exe", @"\\myserver\folder\test.pdf");

However, these files are in a location that the actual users do not have access to. I tried wrapping it with the following:

using (new Impersonator("username", "domain", "password"))
{

}

But I got error:

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll

Additional information: Unknown error (0xfffffffe)

I even tried using ProcessStartInfo and setting username, password and domain there but kept getting:

The directory name is invalid.

So any ideas on how to launch a file (i.e. Doc(x), PDF, JPG, etc.) with giving it credentials of a user that has access to that folder on the network?

Sam
  • 7,252
  • 16
  • 46
  • 65
user3495483
  • 19
  • 1
  • 6
  • 2
    Where is the `Impersonator` class from? – D Stanley Jul 03 '14 at 20:23
  • Can you just copy the file to a local temp folder and open it normally? – Chris Haas Jul 03 '14 at 20:26
  • 2
    Running Explorer as a different user is not supported - see http://stackoverflow.com/questions/4753279/run-explorer-exe-as-administrator-user-within-windows-7. I would suggest not pursuing this, as even if you get it to work it will be very confusing (if multiple Explorer windows are open, there will be no way to tell which are running as the original user vs. the alternate). – nobody Jul 03 '14 at 20:28
  • @DStanley I just googled it and found this : http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User The code looks rather similar – Aelphaeis Jul 04 '14 at 00:45
  • Official Microsoft method: https://learn.microsoft.com/en-us/dotnet/api/system.security.principal.windowsimpersonationcontext – Mike Lowery Jun 17 '20 at 20:31

0 Answers0