locked
Displaying text or a dialogue box during Powershell execution on page. RRS feed

  • Question

  • User705223197 posted

    I'm hoping this is pretty straight forward. I wish to display a textbox or dialopgbox while the powershell call is executed, completes and then the page is refreshed. Basically to provide an indicator that the web application is doing something while the PS completes and then the page refreshes.

    The code is called via a LinkButton as below. I have some Response;.Writes which I used prior to the Page.Response.Redirect just to check my evaluations worked. I hoping this is something really simple!


    protected void ResultGrid_RowCommand(object sender, GridViewCommandEventArgs e) { //Response.Write(ResultGrid.SelectedValue.ToString()); if (e.CommandName == "Logoff") { //Your code //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true); string[] arg = new string[2]; arg = e.CommandArgument.ToString().Split(';'); Session["uid"] = Convert.ToInt32(arg[0]); Session["DesktopGroupName"] = arg[1]; int numVal = -1; numVal = Convert.ToInt32(Session["uid"]); Response.Write(e.CommandArgument.ToString()); Response.Write(arg[0].ToString() + "<br/>"); Response.Write(arg[1].ToString() + "<br/>"); Response.Write(Session["uid"] + " " + Session["DesktopGroupName"]); // Initialize PowerShell engine var shell2 = PowerShell.Create(); // Add the script to the PowerShell object // shell.Commands.AddScript(Input.Text); //shell2.Commands.AddCommand("C:\\Local_Scripts\\sessionkill.ps1"); shell2.Commands.AddCommand("e:\\wwwroot\\ctxrep2csharp\\Scripts\\sessionkill.ps1"); // Add Params // shell.Commands.AddParameter(null,User.Identity.Name); shell2.Commands.AddArgument(Convert.ToInt32(arg[0])); //shell2.Commands.AddArgument(Session["uid"]); //shell2.Commands.AddArgument(Session["uid"] + " " + Session["DesktopGroupName"]); // Execute the script var results = shell2.Invoke(); //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "alert('your message');"); //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["uid"] + "');", true); System.Threading.Thread.Sleep(10000); Page.Response.Redirect(Page.Request.Url.ToString(), true); //Response.Write("<script language='javascript'>window.alert(arg[1].ToString() +' Session has been logged off.');window.location='Default.aspx';</script>"); //Response.Redirect(Request.RawUrl); //ClientScript.RegisterStartupScript(this.GetType(), "LoadParent", "<script language=javascript>window.parent.location.reload();</script>"); } if (e.CommandName == "Reboot") { //Your code //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true); string[] arg = new string[2]; arg = e.CommandArgument.ToString().Split(';'); Session["uid"] = Convert.ToInt32(arg[0]); Session["VDI"] = arg[1].ToString().Substring(10, 14); int numVal = -1; numVal = Convert.ToInt32(Session["uid"]); Response.Write(e.CommandArgument.ToString()); Response.Write(arg[0].ToString() + "<br/>"); Response.Write(arg[1].ToString() + "<br/>"); Response.Write(Session["uid"] + " " + Session["VDI"]); // Initialize PowerShell engine var shell2 = PowerShell.Create(); // Add the script to the PowerShell object // shell.Commands.AddScript(Input.Text); //shell2.Commands.AddCommand("C:\\Local_Scripts\\sessionkill.ps1"); shell2.Commands.AddCommand("e:\\wwwroot\\ctxrep2csharp\\Scripts\\sessionkillvdi.ps1"); // Add Params // shell.Commands.AddParameter(null,User.Identity.Name); shell2.Commands.AddArgument(arg[1]); //shell2.Commands.AddArgument(Session["uid"]); //shell2.Commands.AddArgument(Session["uid"] + " " + Session["DesktopGroupName"]); // Execute the script var results = shell2.Invoke(); //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "alert('your message');"); //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["uid"] + "');", true); System.Threading.Thread.Sleep(15000); Page.Response.Redirect(Page.Request.Url.ToString(), true); } //Page.Response.Redirect(Page.Request.Url.ToString(), true); }

    thanks in advance!

    Tuesday, March 3, 2020 1:41 PM

Answers

  • User475983607 posted

    When I think about it; I just want to call a message / banner / popup that states "please wait .." after the powershell call

    You have two choices.  Follow the recommendation and update the DOM right before making the request that kicks off the powershell script.  The server response will refresh the content.  This is the easiest approach.

    Or modify the server code to kick off a background thread that executes the powershell script.  This allows the code behind to return a response  with the "please wait..." message while the powershell script is running.

    You'll need to design and write code that checks when the powershell script has completed.  A database table can be used to store the powershell script's progress.  A JavaScript timer can be configured to send HTTP requests to read the database table. 

    Your struggling with HTTP fundamentals and might be interested in learning the protocol which should help you solve this standard web development problem. 

    https://www.w3schools.com/whatis/whatis_http.asp

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 7, 2020 3:00 PM

All replies

  • User475983607 posted

    Powershell runs on the server.  At least two 2 HTTP requests are required.  One to start the powershell script and one to monitor the script's progress (long polling). 

    Tuesday, March 3, 2020 2:10 PM
  • User705223197 posted

    Hmm so. I'm being far to simplistic in thinking I can just generate a dialogbox with some text content once the button call is made prior to then executing the PS via 

    var results = shell2.Invoke();

    I do not need to monitor the PS progress; just throw a dialogbox before the script is called. The page refreshes via

    Page.Response.Redirect(Page.Request.Url.ToString(), true);

    once the PS script completes.

    Tuesday, March 3, 2020 3:24 PM
  • User475983607 posted

    darkgen

    Hmm so. I'm being far to simplistic in thinking I can just generate a dialogbox with some text content once the button call is made prior to then executing the PS via 

    var results = shell2.Invoke();

    I do not need to monitor the PS progress; just throw a dialogbox before the script is called. The page refreshes via

    Page.Response.Redirect(Page.Request.Url.ToString(), true);

    once the PS script completes.

    You misunderstand how web applications (HTTP) work.

    An initial HTTP request starts the poweshell script and returns a response to the client.  The client makes successive HTTP request to check on the status of the powershell script.  A database table can be used to store the powershell script process.  

    Otherwise, look into SignalR which uses a persistent Web Socket connection but you'll need to redesign the feature as a JavaScript application. 

    If all you want to do is throw up a dialog, modal, or just HTML while the powershell shell script runs then simply do so.  The redirect will overwrite the dialog, modal, or HTML content.

    Tuesday, March 3, 2020 4:13 PM
  • User705223197 posted

    OK; so forgive my denseness. The rowcommand is called via LnkButton

    <asp:LinkButton ID="Logoff" runat="server" OnClientClick="return confirm('Are you sure you want to forcibly log off this session? Any unsaved work will be lost!. Please allow for the page to refresh if confirmed.')"
    CommandName="Logoff" CommandArgument='<%# Eval("Uid") + ";" +Eval("DesktopGroupName")%>'><img src="Images\logoffmin.png" alt="Logoff" /></asp:LinkButton>

    I'm struggling how or where you make that call to throw a dialog. I'll assume not in the codebehind?

    protected void ResultGrid1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
    
    //throw dialog through some code here?
     if (e.CommandName == "Logoff")
    {
    //Powershell code is executed here, followed by refresh.

    Tuesday, March 3, 2020 4:45 PM
  • User475983607 posted

    The code behind is too late.  This has to be done in JavaScript along with the confirm dialog.  Move the logic to a JavaScript function.

    Tuesday, March 3, 2020 5:46 PM
  • User1535942433 posted

    Hi darkgen,

    Accroding to your description and codes,as far as I think,I suggest you could display text before refreshing page.The redirect will overwrite the  dialogue box,so I suggest you could use javascript in your code behind.

    More details,you could refer to below codes:

    Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "alert('Error message');", true);
                string strLoginPage = "2160555.aspx";
    
                string scriptText = "window.location='" + Request.ApplicationPath + strLoginPage + "'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect",scriptText, true);

    Best regards,

    Yijing Sun

    Wednesday, March 4, 2020 5:28 AM
  • User705223197 posted

    Hmm ok; Thanks for your replies. I understand Javascript is the way to go; I just need to work out and when I plug it in to the code. Sounds like I need to change the method for the button call. Not really sure where to start but thanks!

    aspx

     <asp:GridView ID="ResultGrid" runat="server" DataKeyNames="Uid,DesktopGroupName" OnRowDataBound="ResultGrid_RowDataBound" OnRowCommand="ResultGrid_RowCommand" AutoGenerateColumns="False" OnSelectedIndexChanged="ResultGrid_SelectedIndexChanged" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" Width="1000px" Font-Size="X-Small">
    <AlternatingRowStyle BackColor="PaleGoldenrod" />
    <Columns>
    <asp:BoundField DataField="UserFullName" HeaderText="MUDID" />
    <asp:BoundField DataField="BrokeringTime" HeaderText="SessionStart" />
    <asp:BoundField DataField="ClientName" HeaderText="Client" />
    <asp:BoundField DataField="DesktopGroupName" HeaderText="CTXDG" />
    <asp:BoundField DataField="LaunchedViaPublishedName" HeaderText="CTXApp" />
    <asp:BoundField DataField="SessionState" HeaderText="State" />
    <asp:BoundField DataField="Uid" HeaderText="Uid" />
    <asp:BoundField DataField="MachineName" HeaderText="CTXServer" />
    <asp:BoundField DataField="ENV" HeaderText="ENV" />
    <asp:TemplateField HeaderText="Action" HeaderStyle-CssClass="Logoff" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:LinkButton ID="Logoff" runat="server" OnClientClick="return confirm('Are you sure you want to forcibly log off this session? Any unsaved work will be lost!. Please allow for the page to refresh if confirmed.')"
    CommandName="Logoff" CommandArgument='<%# Eval("Uid") + ";" +Eval("DesktopGroupName")%>'><img src="Images\logoffmin.png" alt="Logoff" /></asp:LinkButton>
    <asp:LinkButton ID="Reboot" runat="server" OnClientClick="return confirm('Are you sure you want to forcibly restart this virtual desktop? Any unsaved work will be lost!. Please allow for the page to refresh if confirmed and several minutes prior to attempting to log back on.')"
    CommandName="Reboot" CommandArgument='<%# Eval("Uid") + ";" +Eval("MachineName")%>' Text="Send" Visible='<%# Eval("MachineName").ToString().Contains("WVDI" )? true : false %>'> <img src="Images\Reboot.png" alt="Logoff" /> </asp:LinkButton>
    </ItemTemplate>
    <HeaderStyle CssClass="Logoff"></HeaderStyle> <ItemStyle HorizontalAlign="Center"></ItemStyle>
    </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="Tan" />
    <HeaderStyle BackColor="Orange" Font-Bold="True" />
    <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
    <SortedAscendingCellStyle BackColor="#FAFAE7" />
    <SortedAscendingHeaderStyle BackColor="#DAC09E" />
    <SortedDescendingCellStyle BackColor="#E1DB9C" />
    <SortedDescendingHeaderStyle BackColor="#C2A47B" />
    </asp:GridView>

    CodeBehind

    protected void ResultGrid_RowCommand(object sender, GridViewCommandEventArgs e)
            {
    
                //Response.Write(ResultGrid.SelectedValue.ToString());
    
                if (e.CommandName == "Logoff")
                {
                    //Your code
    
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true);
    
    
                    string[] arg = new string[2];
                    arg = e.CommandArgument.ToString().Split(';');
                    Session["uid"] = Convert.ToInt32(arg[0]);
                    Session["DesktopGroupName"] = arg[1];
    
                    int numVal = -1;
                    numVal = Convert.ToInt32(Session["uid"]);
                    Response.Write(e.CommandArgument.ToString());
                    Response.Write(arg[0].ToString() + "<br/>");
                    Response.Write(arg[1].ToString() + "<br/>");
                    Response.Write(Session["uid"] + " " + Session["DesktopGroupName"]);
    
                    // Initialize PowerShell engine
                    var shell2 = PowerShell.Create();
    
                    // Add the script to the PowerShell object
                    // shell.Commands.AddScript(Input.Text);
                    //shell2.Commands.AddCommand("C:\\Local_Scripts\\sessionkill.ps1");
                    shell2.Commands.AddCommand("e:\\wwwroot\\ctxrep2csharp\\Scripts\\sessionkill.ps1");
    
                    // Add Params
                    // shell.Commands.AddParameter(null,User.Identity.Name);
                    shell2.Commands.AddArgument(Convert.ToInt32(arg[0]));
                    //shell2.Commands.AddArgument(Session["uid"]);
                    //shell2.Commands.AddArgument(Session["uid"] + " " + Session["DesktopGroupName"]);
    
                    // Execute the script
    
                    var results = shell2.Invoke();
    
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "alert('your message');");
    
                    //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["uid"] + "');", true);
                    System.Threading.Thread.Sleep(10000);
                    Page.Response.Redirect(Page.Request.Url.ToString(), true);
    
                    //Response.Write("<script language='javascript'>window.alert(arg[1].ToString() +' Session has been logged off.');window.location='Default.aspx';</script>");
    
                    //Response.Redirect(Request.RawUrl);
                    //ClientScript.RegisterStartupScript(this.GetType(), "LoadParent", "<script language=javascript>window.parent.location.reload();</script>");
                }
    
                if (e.CommandName == "Reboot")
                {
                    //Your code
    
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true);
    
    
                    string[] arg = new string[2];
                    arg = e.CommandArgument.ToString().Split(';');
                    Session["uid"] = Convert.ToInt32(arg[0]);
                    Session["VDI"] = arg[1].ToString().Substring(10, 14);
    
                    int numVal = -1;
                    numVal = Convert.ToInt32(Session["uid"]);
                    Response.Write(e.CommandArgument.ToString());
                    Response.Write(arg[0].ToString() + "<br/>");
                    Response.Write(arg[1].ToString() + "<br/>");
                    Response.Write(Session["uid"] + " " + Session["VDI"]);
    
                    // Initialize PowerShell engine
                    var shell2 = PowerShell.Create();
    
                    // Add the script to the PowerShell object
                    // shell.Commands.AddScript(Input.Text);
                    //shell2.Commands.AddCommand("C:\\Local_Scripts\\sessionkill.ps1");
                    shell2.Commands.AddCommand("e:\\wwwroot\\ctxrep2csharp\\Scripts\\sessionkillvdi.ps1");
    
                    // Add Params
                    // shell.Commands.AddParameter(null,User.Identity.Name);
                    shell2.Commands.AddArgument(arg[1]);
                    //shell2.Commands.AddArgument(Session["uid"]);
                    //shell2.Commands.AddArgument(Session["uid"] + " " + Session["DesktopGroupName"]);
    
                    // Execute the script
    
                    var results = shell2.Invoke();
    
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "alert('your message');");
    
                    //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["uid"] + "');", true);
                    System.Threading.Thread.Sleep(15000);
                    Page.Response.Redirect(Page.Request.Url.ToString(), true);
                }
                //Page.Response.Redirect(Page.Request.Url.ToString(), true);
            }

    TIA.

    Wednesday, March 4, 2020 7:07 AM
  • User1535942433 posted

    Hi darkgen,

    Accroding to you description,I suggest you could alert before refresh the page in  gridview_command.You could alert then wait minutes to refresh the page accroding to your requirments.

    More details,you could refer to below codes:

    ASPX:

     <asp:GridView ID="ResultGrid" runat="server" DataKeyNames="Uid,DesktopGroupName" OnRowDataBound="ResultGrid_RowDataBound"  OnRowCommand="ResultGrid_RowCommand" AutoGenerateColumns="False" OnSelectedIndexChanged="ResultGrid_SelectedIndexChanged" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" Width="1000px" Font-Size="X-Small">
                    <AlternatingRowStyle BackColor="PaleGoldenrod" />
                    <Columns>
                        <asp:BoundField DataField="UserFullName" HeaderText="MUDID" />
                        <asp:BoundField DataField="BrokeringTime" HeaderText="SessionStart"  />
                        <asp:BoundField DataField="ClientName" HeaderText="Client"  />
                        <asp:BoundField DataField="DesktopGroupName" HeaderText="CTXDG" />
                        <asp:BoundField DataField="LaunchedViaPublishedName" HeaderText="CTXApp" />
                        <asp:BoundField DataField="SessionState" HeaderText="State"  />
                        <asp:BoundField DataField="Uid" HeaderText="Uid"  />
                        <asp:BoundField DataField="MachineName" HeaderText="CTXServer"  />
                        <asp:BoundField DataField="ENV" HeaderText="ENV"  />
                        <asp:TemplateField HeaderText="Action" HeaderStyle-CssClass="Logoff" ItemStyle-HorizontalAlign="Center">
                                                        <ItemTemplate>
                                                            <asp:LinkButton ID="Logoff" runat="server"
                                                                CommandName="Logoff" CommandArgument='<%# Eval("Uid") + ";" +Eval("DesktopGroupName")%>'><img src="Images\logoffmin.png" alt="Logoff" /></asp:LinkButton>
                                                            <asp:LinkButton ID="Reboot" runat="server" OnClientClick="return confirm('Are you sure you want to forcibly restart this virtual desktop? Any unsaved work will be lost!. Please allow for the page to refresh if confirmed and several minutes prior to attempting to log back on.')"
                                                               CommandName="Reboot" CommandArgument='<%# Eval("Uid") + ";" +Eval("MachineName")%>' Text="Send" Visible='<%# Eval("MachineName").ToString().Contains("WVDI" )? true : false %>'> <img src="Images\Reboot.png" alt="Logoff" /> </asp:LinkButton>
                                                        </ItemTemplate>
                                                        <HeaderStyle CssClass="Logoff"></HeaderStyle> <ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                    </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="Tan" />
                    <HeaderStyle BackColor="Orange" Font-Bold="True" />
                    <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                    <SortedAscendingCellStyle BackColor="#FAFAE7" />
                    <SortedAscendingHeaderStyle BackColor="#DAC09E" />
                    <SortedDescendingCellStyle BackColor="#E1DB9C" />
                    <SortedDescendingHeaderStyle BackColor="#C2A47B" />
                </asp:GridView>

    Code-behind:

    protected void ResultGrid_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "Logoff")
                {
                    //Your code
    
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true);
    
    
                    string[] arg = new string[2];
                    arg = e.CommandArgument.ToString().Split(';');
                    Session["uid"] = Convert.ToInt32(arg[0]);
                    Session["DesktopGroupName"] = arg[1];
    
                    int numVal = -1;
                    numVal = Convert.ToInt32(Session["uid"]);
                    Response.Write(e.CommandArgument.ToString());
                    Response.Write(arg[0].ToString() + "<br/>");
                    Response.Write(arg[1].ToString() + "<br/>");
                    Response.Write(Session["uid"] + " " + Session["DesktopGroupName"]);
    
                    // Initialize PowerShell engine
                    var shell2 = PowerShell.Create();
    
                    //// Add the script to the PowerShell object
                    //// shell.Commands.AddScript(Input.Text);
                    ////shell2.Commands.AddCommand("C:\\Local_Scripts\\sessionkill.ps1");
                    shell2.Commands.AddCommand("e:\\wwwroot\\ctxrep2csharp\\Scripts\\sessionkill.ps1");
    
                    //// Add Params
                    //// shell.Commands.AddParameter(null,User.Identity.Name);
                    //shell2.Commands.AddArgument(Convert.ToInt32(arg[0]));
                    ////shell2.Commands.AddArgument(Session["uid"]);
                    ////shell2.Commands.AddArgument(Session["uid"] + " " + Session["DesktopGroupName"]);
    
                    //// Execute the script
    
                    //var results = shell2.Invoke();
    
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "alert('your message');");
    
                    //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["uid"] + "');", true);
                    System.Threading.Thread.Sleep(10000);
                    //Page.Response.Redirect(Page.Request.Url.ToString(), true);
                    //Page.ClientScript.RegisterStartupScript(Page.GetType(), "my", "alert('Error message');", true);
                    /*string strLoginPage = "2160555.aspx"; */// getting page url from web.config;
    
                    string scriptText = "<script>if(window.confirm('Are you sure?')){window.location.href='2164676.aspx'}</script>";
                    ClientScript.RegisterClientScriptBlock(Page.GetType(), "Confirm", scriptText,false);
    
                    //Response.Write("<script language='javascript'>window.alert(arg[1].ToString() +' Session has been logged off.');window.location='Default.aspx';</script>");
    
                    //Response.Redirect(Request.RawUrl);
                    //ClientScript.RegisterStartupScript(this.GetType(), "LoadParent", "<script language=javascript>window.parent.location.reload();</script>");
                }
    
                if (e.CommandName == "Reboot")
                {
                    //Your code
    
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('User details saved sucessfully'); window.open('frmDisplayUsers.aspx');", true);
    
    
                    string[] arg = new string[2];
                    arg = e.CommandArgument.ToString().Split(';');
                    Session["uid"] = Convert.ToInt32(arg[0]);
                    Session["VDI"] = arg[1].ToString().Substring(10, 14);
    
                    int numVal = -1;
                    numVal = Convert.ToInt32(Session["uid"]);
                    Response.Write(e.CommandArgument.ToString());
                    Response.Write(arg[0].ToString() + "<br/>");
                    Response.Write(arg[1].ToString() + "<br/>");
                    Response.Write(Session["uid"] + " " + Session["VDI"]);
    
                    // Initialize PowerShell engine
                    //var shell2 = PowerShell.Create();
    
                    //// Add the script to the PowerShell object
                    //// shell.Commands.AddScript(Input.Text);
                    ////shell2.Commands.AddCommand("C:\\Local_Scripts\\sessionkill.ps1");
                    //shell2.Commands.AddCommand("e:\\wwwroot\\ctxrep2csharp\\Scripts\\sessionkillvdi.ps1");
    
                    //// Add Params
                    //// shell.Commands.AddParameter(null,User.Identity.Name);
                    //shell2.Commands.AddArgument(arg[1]);
                    ////shell2.Commands.AddArgument(Session["uid"]);
                    ////shell2.Commands.AddArgument(Session["uid"] + " " + Session["DesktopGroupName"]);
    
                    //// Execute the script
    
                    //var results = shell2.Invoke();
    
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "alert('your message');");
    
                    //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + Session["uid"] + "');", true);
                    System.Threading.Thread.Sleep(15000);
                    Page.Response.Redirect(Page.Request.Url.ToString(), true);
                }
            }

    Result:

    Best regards,

    Yijing Sun

    Tuesday, March 10, 2020 9:25 AM
  • User705223197 posted

    This isn't quite what I mean. 

    I want to show a banner or something, once the prompt is confirmed, until the page will refreshes itself after x number of seconds.

    When I think about it; I just want to call a message / banner / popup that states "please wait .." after the powershell call

    // Execute the script
    // Display banner or popup with text "please wait" var results = shell2.Invoke();
    Tuesday, April 7, 2020 2:24 PM
  • User475983607 posted

    When I think about it; I just want to call a message / banner / popup that states "please wait .." after the powershell call

    You have two choices.  Follow the recommendation and update the DOM right before making the request that kicks off the powershell script.  The server response will refresh the content.  This is the easiest approach.

    Or modify the server code to kick off a background thread that executes the powershell script.  This allows the code behind to return a response  with the "please wait..." message while the powershell script is running.

    You'll need to design and write code that checks when the powershell script has completed.  A database table can be used to store the powershell script's progress.  A JavaScript timer can be configured to send HTTP requests to read the database table. 

    Your struggling with HTTP fundamentals and might be interested in learning the protocol which should help you solve this standard web development problem. 

    https://www.w3schools.com/whatis/whatis_http.asp

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 7, 2020 3:00 PM