I'm creating a simple file copy program on our intranet to allow users to copy a file to a specific network folder which they do not have access too. I plan to use the the "CopyFile" function from "My.Computer.FileSystem" Namespace since it will uses Windows built-in file copy dialog and progress bar. I assume the user needs to have authentication to this folder. I would like to know if I can have the program run as an authenticated user of this network folder for the file copy to work? Thank you.
Asked
Active
Viewed 9,103 times
1
-
Write a service (with enough privileges) that copies the file to the destination folder when requested. – L.B Feb 05 '14 at 20:30
-
search for impersonation – VladL Feb 05 '14 at 20:32
-
What about WindowsIdentity.Impersonate? Will this accomplish the task without a separate service (or process as mentioned below)? [edit] Thanks Vlad, you posted right before I commented. – merlot Feb 05 '14 at 20:35
1 Answers
1
You need to start a separate process for that. You can use Process.Start(...)
http://msdn.microsoft.com/en-us/library/sxf2saat%28v=vs.110%29.aspx
EDIT:
based on your comment I did also a quick check up on impersonation. This from Matt Johnson post seems promising!
-
-
I guess that is actually what he/she wants, as mentionend "which they do not have access to" – toATwork Feb 05 '14 at 20:33
-
So the application I would have the user start from their desktop is actually the process I write, which will then run my simple program with the proper credentials? – merlot Feb 05 '14 at 20:34
-
@merlot that is how I understood you. The user starts a program, which then itself starts your application with different credentials. Yes. – toATwork Feb 05 '14 at 20:36
-
-
I found an issue with Impersonation. When I use the OpenFileDialog, it shows the mapped network drives as letters only, even though you can browse them. When you try to copy a file it says "path not found". I you go to the driver on the server under network, it works fine. – merlot Feb 06 '14 at 15:32
-
@merlot are you doing the copy also in the impersonation part? It looks like for the user which is doing the copy that network path is not available – toATwork Feb 06 '14 at 16:48
-
@toATwork Yes, I copy in the impersonation. I tried using the OpenFileDialog outside of impersonation and get the same issue. I also tried running a process instead of impersonation - same issue. I believe the issue lies in the OpenFileDialog path. I decided I will alter the path to remove the shortcut drive letter and insert the server name into the path - this should work fine. My only issue is if someone maps a drive I don't know about. Since I'm also the network admin, I assign which drive letter maps to which folder on each server. – merlot Feb 06 '14 at 19:10
-
@merlot the OpenFileDialog needs to be in impersonation as well, because the mapped network drives might be different otherwise. I also agree that the UNC path is the way to go. – toATwork Feb 07 '14 at 07:23