启动带有参数的进程
本文关键字:进程 参数 启动 | 更新日期: 2023-09-27 17:53:07
我正在使用进程。从我的网站开始打开我用c#制作的windows窗体应用程序。
我想把我的用户名发送给应用程序。
我该怎么做呢?
您可以通过在start info中分配参数来实现这一点,例如:
var process = new Process
{
StartInfo =
{
FileName = processName,
Arguments = "-username=Alice"
}
};
process.Start();
如果你的进程启动失败,你可能想检查权限,据我所知,在IIS上运行的代码是不允许这样做的。
Process.Start()
有几个重载,其中一个是用于指定命令行参数以及可执行文件的路径。
Process.Start("app.exe", "parameter(s)");
你可以这样做:
Process.Start("MyExe.exe", "arguments");
给你,应该可以工作了
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);
}
}
}