使用IIS服务在活动会话和会话0外执行应用程序

我在IIS上运行asp.net网站上运行服务。 我想用GUI打开Excel文件,所以我必须使用活动会话。

这是我的button点击代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </form> </body> </html> using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using murrayju.ProcessExtensions; namespace WebApplication2 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string x = @"C:\www\zmqpga.com\reports\F.xlsx"; ProcessExtensions.StartProcessAsCurrentUser(x); } } } 

这使得下一个错误http://prntscr.com/g4q1uo

当我使用哈米德Javaheri解决scheme

  System.Diagnostics.Process process1 = new System.Diagnostics.Process(); process1.StartInfo.WorkingDirectory = Request.MapPath("~/"); process1.StartInfo.FileName = process1.StartInfo.FileName = Request.MapPath("F.xlsx"); process1.StartInfo.Arguments = " "; process1.StartInfo.LoadUserProfile = true; process1.Start(); process1.WaitForExit(); process1.Close(); 

这是打开Excel过程(当我看着任务pipe理器)。 但是我需要GUI,所以我必须在活动会话上运行它。 任何人都知道一个简单的方法来这样做? 你可以给我任何示例代码? 我只是不知道。

对于ProcessExtensions,我使用这个https://github.com/murrayju/CreateProcessAsUser

编辑

对于Hamed Javaheri解决scheme:经过大量的尝试,当我使用远程debugging时,我只是卡在process1.Start()和超时后,我得到了process1.WaitForExit()错误,因为

System.dll中发生types“System.InvalidOperationException”的exception,但未在用户代码中处理

附加信息:没有进程与此对象关联。

我会尽力专注于我的问题。 我实际上尝试.xltm文件,运行在IIS上作为服务(会话0,在后台)上运行的asp.net服务器的VBA代码。 问题是什么都没有运行。 我没有读\写\创build文本文件的问题,所以我有正确的权限。

你可以直接运行你的excel文件:

  // Create a Process Object here. System.Diagnostics.Process process1 = new System.Diagnostics.Process(); //Working Directory Of .exe File. process1.StartInfo.WorkingDirectory = Request.MapPath("~/"); //exe File Name. process1.StartInfo.FileName = Request.MapPath("Book1.xlsx"); //Argement Which you have tp pass. process1.StartInfo.Arguments = " "; process1.StartInfo.LoadUserProfile = true; //Process Start on exe. process1.Start(); process1.WaitForExit(); process1.Close();