My WPF app allows users to add "a开发者_JAVA百科ttachments" (Word, Excel, Text documents etc). The app generates Access Denied errors as it attempts to open a file on our company network. The error occurs after Process.Start is executed. The shell application opens (i.e. Notepad for a text file) then the "Access Denied" message appears. Initially I had similar errors attempting to write files but I fixed that problem using the Impersonator class found here.
Here is the problem code:
using (Impersonator impersonator = new Impersonator())
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = pathToDocument;
process.StartInfo.UseShellExecute = true;
process.Start();
}
I get the same error doing this:
using (Impersonator impersonator = new Impersonator())
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = pathToDocument;
process.StartInfo.UserName = "uid";
process.StartInfo.Domain = "domain";
process.StartInfo.Password = new System.Security.SecureString();
foreach (Char c in "password")
{
process.StartInfo.Password.AppendChar(c);
}
process.StartInfo.UseShellExecute = false;
process.Start();
}
The deployed app fails even when I hard code my own user id and password (I have "full control" permissions to read, write, execute etc). Everything works fine if I change the document path to be a different shared drive that has relaxed security (where everyone is granted full control). The app is deployed with basic ClickOnce settings. The app is not installed on the users machine - it is available online only. What should I do to prevent Access Denied errors?
Thanks in advance.
精彩评论