开发者

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 us开发者_开发问答ername.

So how can I do that?


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.


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)");


You can use this:

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


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);
    }
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜