C# process.start parameters

2.1k views Asked by At

We can create a shortcut to an .exe file.

As you know, shortcut files can contain parameters.

I want to build a program that automatically assigns parameters using C # code.

Here is my code:

    private void button4_Click(object sender, EventArgs e)
    {
        HttpWebRequest req =
        WebRequest.Create("http://test.com/contact_ip.txt") as HttpWebRequest;

        HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

        using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
        {
            string ResponseText = sr.ReadToEnd();
            //ResponseText

            System.Diagnostics.Process.Start(".\\folder\\test.exe");
            // e.g.)) test.exe 127.0.0.1(ResponseText) 1234(port)
        }
    }

How do I include the IP address and port at test.exe?

e.g.)) .\folder\test.exe 127.0.0.1 4455

e.g.2)) Var ResponseText = ip Address
1

There are 1 answers

5
NicoRiff On BEST ANSWER

You can try this:

private void button4_Click(object sender, EventArgs e)
{
    HttpWebRequest req =
    WebRequest.Create("http://test.com/contact_ip.txt") as HttpWebRequest;

    HttpWebResponse resp = req.GetResponse() as HttpWebResponse;

    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
    {
        string ResponseText = sr.ReadToEnd();
        //ResponseText

        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo.FileName = @".\\folder\\test.exe";
        proc.StartInfo.Arguments = "127.0.0.1 4455";
        proc.Start();
    }
}