0

I have a page file (aspx) and a (.cs file) where the user can input some rules to block or unblock lines of production. When the user finishes making any changes, he/she presses a buuton to save the data. First it makes a .txt file with all the rules that were made or changed.

After that I need to execute a .exe file (made in Python) that takes this information and makes another text file by reading all the lines of production and all the orders (2 other files) to Block productions in certains lines. This is already done.

My problem is that I can't execute this .exe file. I have tried with this code in the .cs file

ScriptManager.RegisterStartupScript(this, GetType(), "blockinglines", "BlockLine()", true);

And BlockLine function is this

<script>
    function BlockLine(){
        var shell = new ActiveXObject("WScript.Shell");               
        var bat = "\"C:\\inetpub\\wwwroot\\BlockLine\\Bin\\dist\\BLines.exe\" ";
        shell.Run(bat);
    }
</script>

But I can't run it. Is there any other solution to make this or an error I have made in the code??

7
  • How does this line of code attempt to execute an .exe file? What is BlockLine() and what does it do? It's really not clear at all what you're trying to accomplish here or how it needs to work. Commented Nov 13, 2015 at 16:56
  • 1
    Running javascript is one thing. Running an exe is another. You won't be able to do it. This is by design. It is an important security feature of every major web browser. You will not find any work arounds that allow you to run exe files from a web page. You need to go way back to the drawing board on this whole plan. Commented Nov 13, 2015 at 16:56
  • Joel Coehoom I had something that worked for handbreak video converter exe some time ago. But yeah, find a dll for your exe, OP and use it ... Commented Nov 13, 2015 at 16:59
  • @David I just edited to put the code for BlockLine() Commented Nov 13, 2015 at 17:01
  • 1
    @JoshuaCazares: And how exactly does this code fail? Is the JavaScript executing at all? Is the browser blocking the ActiveXObject? Is there an error in the JavaScript console at all? Does that file even exist on the client machine? Commented Nov 13, 2015 at 17:03

1 Answer 1

3

Replace this:

ScriptManager.RegisterStartupScript(this, GetType(), "blockinglines", "BlockLine()", true);

With this:

Process.Start(@"C:\inetpub\wwwroot\BlockLine\Bin\dist\BLines.exe");

Then get rid of the script section entirely. You may also need to add a reference to System.Diagnostics.

And remember that this only works when you want your BLines program to run on the web server. If you want this to run on the browser, you're completely out of luck, and for good reason.

Sign up to request clarification or add additional context in comments.

3 Comments

It showed me this error: System.Exception: Access to the path 'C:\inetpub\wwwroot\BloqueoLinea\App_Data\BloqLines.txt' is denied.
Think about what user account is running your web site, and make sure that account has access to this path.
I just gave full control to the IIS Users, and it generated the text file, thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.