Tuesday 17 September 2013

How to Execute EXE file in ASP.NET

protected void Btn_Execute_Click(object sender, EventArgs e)
    {
        try
        {
            Process myprocess = new Process();
            myprocess.StartInfo.FileName = ExePath;
            myprocess.StartInfo.FileName = @"D:\exefilename.exe";
            myprocess.Start();
            td_Mesg.Visible = true;
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }
        finally
        {
            ;
        }
      
    }
    protected void Btn_Stop_Click(object sender, EventArgs e)
    {
        try
        {
            Process[] p = Process.GetProcessesByName("processname");
            for (int i = 0; i < p.Length; i++)
            {
                p[i].Kill();
            }
            if (p.Length > 0)
            {
                td_Mesg.InnerHtml = "EXE stopped successfully ...";
            }
            else
            {
                td_Mesg.InnerHtml = "Currently EXE is not running ...";
            }


        }
        catch (Exception ex)
        {
            td_Mesg.InnerHtml = ex.Message.ToString();
        }
        finally
        {
            ;
        }

    }

No comments:

Post a Comment

C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...