locked
How to call windows exe file in ASP.NET Application which has been hosted in IIS RRS feed

  • Question

  • User-1024101449 posted

    Hi,

    How to call windows exe file in ASP.NET Application which has been hosted in IIS.?

    The exe does, fetching records from SAP and keep it in local folder.

    I have been facing the below issues.

    1) I am not able to call the exe file in ASP.NET file.
    2) I am not able to connect SAP through ASP.NET which is hosted in IIS.

    Can any one give idea/suggestion, how to proceed above scenario...?

    Tuesday, August 21, 2018 7:11 AM

Answers

  • User283571144 posted

    Hi gani7787,

    Is it possilbe to maintain exe file in ASP.NET Application or somewhere keep in the project..?

    As far as I know, we could call the exe file in the asp.net application.

    We could use System.Diagnostics.Process's start method to run the exe.

    But the exe should inside the server and the application pool should have the permission to access the exe.

    Besides, you should make sure the exe could run well to connect to the SAP.

    About how to run exe in asp.net application, you could refer to below codes:

            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
            protected void btnCall_Click(object sender, EventArgs e)
            {
                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = @"D:\Programs\Microsoft VS Code\Code.exe";
                info.Arguments = "";
                info.WindowStyle = ProcessWindowStyle.Normal;
                Process pro = Process.Start(info);
                pro.WaitForExit();
            }
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 22, 2018 5:27 AM

All replies

  • User-511826081 posted

    Hi,

    Do not clearly understand from your description where is a problem.

    Regularly use a side tool from IIS. From ASP and from WCF - there are no difference.

    There also are a very few things which need to remember.

    EXE file MUST be accessible by IIS - look on user permission and option to access directories.

    That's all.

    Code to run EXE in Windows are standart:

    using System.Diagnostics;
    
    
    string toolsDir = System.Web.Hosting.HostingEnvironment.MapPath(ToolsDir);
    string toolexe = Path.Combine(toolsDir, ToolName);
    
    ProcessStartInfo psi = new ProcessStartInfo(toolexe);
    psi.WindowStyle = ProcessWindowStyle.Hidden;
    psi.CreateNoWindow = true;
    psi.Arguments = "-d:Dummy";
    Process p = Process.Start(psi);

    Tuesday, August 21, 2018 9:09 AM
  • User-1024101449 posted

    i want to call exe from asp.net application.

    This ASP.NET application hosted in IIS Web Server.

    purpose of exe tool : fetch data from SAP and keep it in local folder.

    In ASP.NET we can't directly call and fetch data from SAP.

    that is the reason, we are calling exe and from exe we are processing further action.

    Is it possilbe to maintain exe file in ASP.NET Application or somewhere keep in the project..?

    Tuesday, August 21, 2018 10:30 AM
  • User475983607 posted

    gani7787

    In ASP.NET we can't directly call and fetch data from SAP.

    That does not make a bit of sense.  If you can fetch the data with an exe you should be able to do the same in your web app.  Both the web app and the exe are running on the same machine.

    Anyway, you can use Process.Start to kickoff an exe but that has its own issue in a web application.  The web identity must have right to run the exe.  There can be concurrency issues. 

    https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.start?redirectedfrom=MSDN&view=netframework-4.7.2#overloads

    Perhaps you can meet with your team and and SAP to discuss possible solutions.

    Tuesday, August 21, 2018 10:56 AM
  • User-511826081 posted

    i want to call exe from asp.net application.

    -----

    code to run an EXE from IIS was provided above.

    Assumed that - 'ToolsDir' is a virtual folder on IIS. 'ToolName' - name of the EXE file in 'ToolsDir'.

    If you need to wait when EXE complete his work and exit add

    p.WaitForExit();

    Just have noted - extraction of your data may cause a timeout on the page/service.

    If this happen - you need to use some notification or pulling to determine when data are ready.

    Tuesday, August 21, 2018 10:57 AM
  • User-511826081 posted

    The web identity must have right to run the exe.

    -----

    Try this:

    psi.Domain = domain;
    psi.UserName = userName;
    psi.Password = password;
    Tuesday, August 21, 2018 11:15 AM
  • User283571144 posted

    Hi gani7787,

    Is it possilbe to maintain exe file in ASP.NET Application or somewhere keep in the project..?

    As far as I know, we could call the exe file in the asp.net application.

    We could use System.Diagnostics.Process's start method to run the exe.

    But the exe should inside the server and the application pool should have the permission to access the exe.

    Besides, you should make sure the exe could run well to connect to the SAP.

    About how to run exe in asp.net application, you could refer to below codes:

            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
            protected void btnCall_Click(object sender, EventArgs e)
            {
                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = @"D:\Programs\Microsoft VS Code\Code.exe";
                info.Arguments = "";
                info.WindowStyle = ProcessWindowStyle.Normal;
                Process pro = Process.Start(info);
                pro.WaitForExit();
            }
    

    Result:

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 22, 2018 5:27 AM
  • User-1024101449 posted

    excellent....Thanks...

    Thursday, August 23, 2018 10:37 AM