1

I'm going to have an ASP.NET MVC application that will run on many clients, all of which have their own local version of IIS running. I'm trying to open a PowerPoint file with Process.Start(). The PowerPoint is successfully opening (I can see it in Task Manager) but it is running in the background and I would like it to open in the foreground.

In order to start the application I'm using the following code:

string powerPointPath = @"C:\Program Files (x86)\Microsoft Office\root\Office16\POWERPNT.EXE";
string powerPointFilePath = "\"" + filePath;

Process powerPoint = new Process();
powerPoint.StartInfo.FileName = powerPointPath;
powerPoint.StartInfo.Arguments = " /S " + filePath;
powerPoint.Start();

Since I'm using a local instance of IIS, I made sure to grant read permissions for the PowerPoint executable to the IIS APPPOOL\DefaultAppPool user. Is there any way to ensure that PowerPoint runs in the foreground?

Edit: I'm able to run this code without an issue when using IIS Express in Visual Studio (in which case the application is using the MYNAME\myname user permissions) but it does not seem to work equivalently when using Local IIS (i.e. when the application is using the IIS APPPOOL\DefaultAppPool user).

dumbchemistry
  • 384
  • 1
  • 5
  • 21

2 Answers2

1

Problem is that IIS runs under a service account, and you need the PowerPoint process to start as the currently logged on interactive user-- whoever that is.

Maybe try this answer to see if it works with an IIS process as well? (But instead of CreateProcessAsUser maybe use this approach).

Another approach would be to write something completely separate that would run under the current user's system tray, and have it "listen" for a signal that is sent by the web application, e.g. open a named pipe or even poll a directory for a file. For example, your web app could copy a PowerPoint file into an agreed folder, and the tray application would monitor it (using FileSystemWatcher) and automatically open anything it sees in the folder. The tray app runs as the interactive user so there is no cross-user boundary to overcome.

Community
  • 1
  • 1
John Wu
  • 50,556
  • 8
  • 44
  • 80
  • Great, that makes sense, thanks for the help! For future readers, I was able to open it using the library from [this](http://stackoverflow.com/a/24122826/3850567) answer from the first link @John Wu referenced. – dumbchemistry Sep 08 '16 at 16:12
0

Asp.net code runs on server side hence process.Start(); starts the process on server side, you can use activex object for IE or equivalent for other browsers if you want to open on client side

Vinay Pandey
  • 8,589
  • 9
  • 36
  • 54
  • I'm able to run the above code if I use IIS Express in Visual Studio (in which case the application is running under the `MYNAME\myname` account instead of `IIS APPPOOL\DefaultAppPool`) instead of Local IIS and it does appear that PowerPoint is running (albeit in the background), so, unless I'm completely mistaken (which is a definite possibility), shouldn't it be possible to launch it assuming I have correct permissions? – dumbchemistry Sep 07 '16 at 20:14
  • Thats is in your local machine probably where you have all the permission, there is huge security implication apart from other hurdles, consider some random application deleting all files or doing similar things if everyone is able to execute system command on client machine. Whereas when client installs activex or others its assumed that client is aware of consequences. – Vinay Pandey Sep 07 '16 at 20:21
  • Thanks, I'll look into ActiveX. This application will be running on a bunch of different machines each with their own local instance of IIS and won't be connected to the Internet -- is it still subject to security issues? I know this isn't implementing best practices and would be better suited for a desktop application, but I inherited this project and am unsure of alternatives at this point in development. – dumbchemistry Sep 07 '16 at 20:57
  • I am not sure why you need appliction installed on local for each end user would be interesting if you could share why you are configuring and deploying applicstion on each machine instead of having 1 instance being accessed by any means of network may be lan if not internet. Anyways have a look at https://social.msdn.microsoft.com/Forums/en-US/a5db03be-3748-4f60-af4e-b3568f7ef851/ensure-window-is-foreground-after-processstart?forum=vblanguage havent tried myseld but should help. – Vinay Pandey Sep 07 '16 at 22:14