Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以在WinForms应用程序中运行独立的应用程序?_C#_Winforms_Remote Access_Remote Desktop - Fatal编程技术网

C# 是否可以在WinForms应用程序中运行独立的应用程序?

C# 是否可以在WinForms应用程序中运行独立的应用程序?,c#,winforms,remote-access,remote-desktop,C#,Winforms,Remote Access,Remote Desktop,我需要使用WinForms主机应用程序控制一个独立的应用程序,就像另一个应用程序在远程桌面上运行,而我新开发的主机应用程序就是远程桌面主机一样。CodeProject文章鼓舞人心的是,我的任务可能完成的可能性并不是零。它解释了如何使用“Microsoft终端服务控制类型库”或MSTSCLib.dll来执行此操作 但是,我不想连接到远程桌面。如果有的话,我想连接到同一台机器上的第二个桌面,如果这是独立运行托管应用程序所必需的,或者类似的东西。使用MSTSCLib是否可以实现这一点?如果是的话,我需

我需要使用WinForms主机应用程序控制一个独立的应用程序,就像另一个应用程序在远程桌面上运行,而我新开发的主机应用程序就是远程桌面主机一样。CodeProject文章鼓舞人心的是,我的任务可能完成的可能性并不是零。它解释了如何使用“Microsoft终端服务控制类型库”或
MSTSCLib.dll
来执行此操作

但是,我不想连接到远程桌面。如果有的话,我想连接到同一台机器上的第二个桌面,如果这是独立运行托管应用程序所必需的,或者类似的东西。使用
MSTSCLib
是否可以实现这一点?如果是的话,我需要从哪些方面来进一步开发这方面的设计


重要提示:无法访问外部程序代码的限制已不存在。“来宾”程序将仅来自一系列专门定义的程序。

我的一位朋友以前做过这项工作

你应该这样做:

首次导入系统DLL:

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    [DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
    private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
现在声明一个计时器并遵循以下代码:

    private const int GWL_STYLE = (-16);
    private const int WS_VISIBLE = 0x10000000;
    Process p;
 /*Closing Is Timer*/
        private void Closing_Tick(object sender, EventArgs e)
    {


            p.Refresh();
            string a = p.ProcessName;              
                SetParent(p.MainWindowHandle, panel1.Handle);
                SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
              MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);


    }
  void run(string add)
    {
        string addres = add;

        try
        {
            p = Process.Start(addres);
            Thread.Sleep(500); // Allow the process to open it's window
            SetParent(p.MainWindowHandle, panel1.Handle);
            SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
            MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);


        }
        catch
        {
            Closeing.Enabled = false;
            MessageBox.Show(addres + "\n" + "Not Found", "Error",
          MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            Environment.Exit(0);

        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Closeing.Enabled = true;
        run(@textBox1.Text); 
    }
Run方法的输入参数是要在应用程序中运行的程序的路径


希望这有帮助!:)

我的一个朋友以前做过这项工作

你应该这样做:

首次导入系统DLL:

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    [DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)]
    private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
现在声明一个计时器并遵循以下代码:

    private const int GWL_STYLE = (-16);
    private const int WS_VISIBLE = 0x10000000;
    Process p;
 /*Closing Is Timer*/
        private void Closing_Tick(object sender, EventArgs e)
    {


            p.Refresh();
            string a = p.ProcessName;              
                SetParent(p.MainWindowHandle, panel1.Handle);
                SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
              MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);


    }
  void run(string add)
    {
        string addres = add;

        try
        {
            p = Process.Start(addres);
            Thread.Sleep(500); // Allow the process to open it's window
            SetParent(p.MainWindowHandle, panel1.Handle);
            SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISIBLE);
            MoveWindow(p.MainWindowHandle, 0, 0, this.Width, this.Height, true);


        }
        catch
        {
            Closeing.Enabled = false;
            MessageBox.Show(addres + "\n" + "Not Found", "Error",
          MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            Environment.Exit(0);

        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Closeing.Enabled = true;
        run(@textBox1.Text); 
    }
Run方法的输入参数是要在应用程序中运行的程序的路径


希望这有帮助!:)

你是说你想把他们的用户界面嵌入你的用户界面?没有他们的合作,这并不简单。(这与TS完全无关;您需要Windows API方法来重新分配Windows)简短回答不,冗长回答,一切都有可能…@Slaks:这就是为什么ProfK希望“成为本地主机上的TS客户端”而不是重新分配Windows:因为TS可以在没有“托管”UI(通常是这样)的合作下完成。您希望能够在自己的应用程序中打开其他应用程序。对吗?当您收到针对所包装程序中的bug的所有支持调用时,这种错觉就完成了。通常可以使用SetParent()进行monkey操作,Windows具有完全支持的适用于Windows 3.x程序的appcompat。对于一个从未见过Windows版本的程序来说,这在多大程度上仍然有效?你会很难找到答案。你是说你想把他们的UI嵌入到你的UI中?没有他们的合作,这并不简单。(这与TS完全无关;您需要Windows API方法来重新分配Windows)简短回答不,冗长回答,一切都有可能…@Slaks:这就是为什么ProfK希望“成为本地主机上的TS客户端”而不是重新分配Windows:因为TS可以在没有“托管”UI(通常是这样)的合作下完成。您希望能够在自己的应用程序中打开其他应用程序。对吗?当您收到针对所包装程序中的bug的所有支持调用时,这种错觉就完成了。通常可以使用SetParent()进行monkey操作,Windows具有完全支持的适用于Windows 3.x程序的appcompat。对于一个从未见过Windows版本的程序来说,这在多大程度上仍然有效,这是你将很难发现的。