How do I start a process from C#?

后端 未结 12 2009
北荒
北荒 2020-11-22 03:38

How do I start a process, such as launching a URL when the user clicks a button?

相关标签:
12条回答
  • 2020-11-22 04:01
    class ProcessStart
    {
        static void Main(string[] args)
        {
            Process notePad = new Process();
    
            notePad.StartInfo.FileName   = "notepad.exe";
            notePad.StartInfo.Arguments = "ProcessStart.cs";
    
            notePad.Start();
        }
    }
    
    0 讨论(0)
  • 2020-11-22 04:08

    I used the following in my own program.

    Process.Start("http://www.google.com/etc/etc/test.txt")
    

    It's a bit basic, but it does the job for me.

    0 讨论(0)
  • 2020-11-22 04:08

    To start Microsoft Word for example, use this code:

    private void button1_Click(object sender, EventArgs e)
    {
        string ProgramName = "winword.exe";
        Process.Start(ProgramName);
    }
    

    For more explanations, check out this link.

    0 讨论(0)
  • 2020-11-22 04:09

    Include the using System.Diagnostics;.

    And then call this Process.Start("Paste your URL string here!");

    Try something like this:

    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Diagnostics;
    
    namespace btnproce
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
                string t ="Balotelli";
                Process.Start("http://google.com/search?q=" + t);
            }
        }
    }
    

    Please note that it is a sample ASP.NET page as an example. You should try and improvise a little bit.

    0 讨论(0)
  • 2020-11-22 04:13

    You can use the System.Diagnostics.Process.Start method to start a process. You can even pass a URL as a string and it'll kick off the default browser.

    0 讨论(0)
  • 2020-11-22 04:15
    var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "/YourSubDirectory/yourprogram.exe");
    Process.Start(new ProcessStartInfo(path));
    
    0 讨论(0)
提交回复
热议问题