Start A Process With Parameters

I’m Using Process.Start from my website to open a windows form application I made in c#.

I want send to the application my username.

So how can I do that?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can do this by assigning arguments in start info, e.g.:

var process = new Process
      {
          StartInfo =
              {
                  FileName = processName,
                  Arguments = "-username=Alice"
              }
      };
process.Start();

If your process fails to start you might want to check permissions, as far as I am aware code running on IIS is not allowed to do that.

Method 2

Process.Start() has several overloads, one of them is for specifying the command-line arguments along with the path to the executable.

For example:

Process.Start("app.exe", "parameter(s)");

Method 3

You can use this:

Process.Start("MyExe.exe", "arguments");

Method 4

Here you go, should be working

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace SSHPit
{

public partial class MainForm : Form
{       
    [DllImportAttribute("user32.dll")]
    public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
    [DllImport("user32.dll", SetLastError = true)]
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);


    public MainForm()
    {           
        InitializeComponent();
        
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.FileName = "L:\Program Files\putty\putty.exe";
        p.StartInfo.Arguments = "-load "mysession" -ssh 127.0.0.1";
        p.Start();
        p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
        p.WaitForInputIdle();
        while (p.MainWindowHandle == IntPtr.Zero)
        {
           Thread.Sleep(100); 
           p.Refresh();
        }
        SetParent(p.MainWindowHandle, panel1.Handle);
    }
}
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x