Launch a program from ASP.NET C#

前端 未结 5 1239
暗喜
暗喜 2020-12-16 19:29

I have a program (I created) and I want to start it on the server when the webpage loads.

Here is the code I have

public partial class _Default : S         


        
相关标签:
5条回答
  • 2020-12-16 20:02

    Have you tried something like this in Javascript :-

    var shell = new ActiveXObject("Shell.Application");
    var appExe =  @"D:/Path to /My/Program to be run.exe";
    shell.ShellExecute(appExe , "", "", "open", "1");
    
    0 讨论(0)
  • 2020-12-16 20:16

    You could use ProcessStartInfo.

    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = @"D:/Path to /My/Program to be run.exe";
    psi.WorkingDirectory = IO.Path.GetDirectoryName(psi.FileName);
    Diagnostics.Process.Start(psi);
    
    0 讨论(0)
  • 2020-12-16 20:16

    It depends what you're trying to run. Maybe when you run it from your C# app something's missing. You also might not have the correct permissions to run the app from C#. That's all I can really say without knowing what's trying to be run.

    0 讨论(0)
  • 2020-12-16 20:24

    This is a security issue. Running any exe from outside the bin folder poses a security threat. You have to copy the exe you are trying to run in the bin folder.

    0 讨论(0)
  • 2020-12-16 20:25

    It sounds like the application you're trying to run has a user interface. If you're intention is to run this on the server using the ASP.NET application pool account, you will have fewer problems if you design the application as a console app, and guard all access to external resources, like your HMI device, with logged exceptions.

    0 讨论(0)
提交回复
热议问题