.Net ASP button with code behind to open PowerShell and run batch file

0

I have an asp web page in Visual Studio 2017 with an asp button which, when clicked, should run a batch file in Windows PowerShell. The batch file runs NUnit Selenium tests.

The code to open PowerShell and run the batch file works in a non-web-based GUI. I am trying to do the same in a web page but it does not work resulting in:

The program '[10968] iisexpress.exe' has exited with code -1 (0xffffffff). I would be very grateful for any help.
It makes no difference if I run with debugging or without. Sorry, I am new to this!

The .aspx page code follows:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head Runat="server">
    <title>RunTests</title>

    <script src="Scripts/jquery-3.0.0.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>

    <meta name="viewport" content="width=device-width,initial-scale=1"/>  

    <link rel="shortcut icon" href="#"/>

    <link href="Content/bootstrap.css" rel="stylesheet" />
    <link rel="shortcut icon" href="#" />

</head>
<body>
     <script src="Scripts/jquery-3.0.0.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
   <!--Navigation bar-->
<div id="nav-placeholder">

</div>

<script>
$(function(){
  $("#nav-placeholder").load("nav.html");
});
</script>
<!--end of Navigation bar-->
    <br /><br />
    <div class="container">
        <blockquote class="blockquote text-center">
          <p class="h2">Select the tests to run</p>
        </blockquote>
        <br />
    </div>
<div class="card-group">
    <div class="row">
  <div class="col-sm-3">
    <div class="card">
      <div class="card-body">
        <h5 class="card-title">Accessibility</h5>
        <p class="card-text">Run all Accessibiity tests</p>
         <form id="form1" runat="server"> 
        <asp:Button id="Accessibility" class="btn btn-primary" onclick="Accessibility_Click" Text="Accessibility" runat="server"/>
         </form>
      </div>
    </div>
  </div>

The code behind the button:

protected void Accessibility_Click(object sender, EventArgs e)
        {
            Button clickedButton = (Button)sender;

            if (File.Exists("Listings.bat"))

            {

                string filePath = @"C:\Users\Michael\Documents\KompasseraAutomation\KompasseraTests\bin\Debug\";

                File.GetAttributes("Listings.bat");

                string strCmdText = Path.Combine(filePath, "Listings.bat");

                var process = new Process();

                process.StartInfo.UseShellExecute = false;

                process.StartInfo.RedirectStandardOutput = true;

                process.StartInfo.FileName = @"C:\windows\system32\windowspowershell\v1.0\powershell.exe";

                process.StartInfo.Arguments = "\"&'" + strCmdText + "'\"";
            }
        }
asp.net
code-behind
asked on Stack Overflow Jan 22, 2019 by Michael Piraner

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0