0

I have a very simple code, which I am using to test if I can open a specific file. Till now, this is the code I have

string filename = "C:\\anu.txt";
Process myProcess = new Process();
myProcess.StartInfo.FileName = filename;
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.RedirectStandardOutput = false;
myProcess.Start(); 

This code starts a notepad process perfectly, but as user "DefaultAppPool". So, I can see the process in Task manager, but the notepad window doesn't show up. I have no idea what I can do here to fix this. I tried running it as different user, but it still shows up with "DefaultAppPool" user id.

Edit:

Apparently this is a security feature in Vista and higher. :/ So, can't do this anymore. Oh well, time to find a workaround.

jitendragarg
  • 945
  • 1
  • 14
  • 54
  • It is not. Check the question again in both cases. I don't have problem with process not starting. I have problem with process starting under default username. :/ – jitendragarg Apr 20 '16 at 04:51
  • Why do you need to see the Notepad window if you are testing "if I can open a specific file"? What is supposed to happen once the asp.net application is deployed to a server? – Alexander Apr 20 '16 at 08:04
  • I am supposed to open a mail client on user side, and attach the file in the new mail object. I was testing if it is possible to open the msg file on client machine. I want to display this msg file to user, so that he/she can make changes before sending. Here is a link to the actual problem with more details. http://stackoverflow.com/questions/36714879/attaching-auto-generated-pdf-to-email-in-asp-net-app Anyway, as it turn out, this workaround cannot work, so I am off to try something new now. – jitendragarg Apr 20 '16 at 08:09
  • You will not be able to access anything clientside from your C# server-side code! – Alexander Apr 20 '16 at 08:10

1 Answers1

-3

You don't need to write that much of code. You can open a text file just by a single line

Process.Start(@"C:\Users\ankush.jain\Desktop\test.txt");

Process exists in System.Diagnostics namespace.

Ankush Jain
  • 5,654
  • 4
  • 32
  • 57
  • I think you don't understand the question at all. It doesn't matter if I use that many lines or just a single line. It does the same thing. Process starts perfectly, only under the IIS username. I tried your code as is, and same thing. P.S. I do know which namespace to use. ;) – jitendragarg Apr 20 '16 at 04:28
  • http://stackoverflow.com/questions/4679561/system-diagnostics-process-start-not-work-from-an-iis#answer-4679686 – Ankush Jain Apr 20 '16 at 04:43
  • That is a very old and different problem. First off, my system do start the process, worker process can and is starting all kinds of process I throw at it. If I go to task manager, I can see the process there. It is just that it is started by default IIS user, and so not accessible from desktop of logged in user. As for admin service, that does not work anymore. IIS does not require admin service in Win 7 or higher. :) So, that second suggestion is out. Anyway, IIS service has access to whole web app folder and C drive. So, no problem there, really. – jitendragarg Apr 20 '16 at 04:50
  • exact situation like yours http://stackoverflow.com/questions/22171115/iis-8-launch-exe-on-server-via-asp-net – Ankush Jain Apr 20 '16 at 04:57
  • Thanks. That second link is exactly what I am looking for. Turns out it is a security measure, so I will have to find a way to hack around it. :/ – jitendragarg Apr 20 '16 at 05:01