run a foreign exe inside a windows form app

后端 未结 2 1660
猫巷女王i
猫巷女王i 2020-12-18 13:21

i have a c# powered windows form app and i want to run a exe inside it. that program is another seperate executable file. lets say that that exe is not a dot net app, but wr

2条回答
  •  -上瘾入骨i
    2020-12-18 14:02

        [DllImport("user32.dll")]
            static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);    
    
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
    
                    Process p = Process.Start(textBox1.Text);
                    p.WaitForInputIdle();
                    SetParent(p.MainWindowHandle, panel1.Handle);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    }
    

    Reference to fardjad but it can only run small programs like notepad, firefox, safari

提交回复
热议问题