我从Windows服务运行EXE程序,但我看不到表单C#?

时间:2015-06-04 14:57:06

标签: windows service process hidden

我从Windows服务运行另一个程序

private Process RunApp(string _appLocation)
    {
        //Create Process
        Process _ret = new Process();

        _ret.StartInfo.FileName = _appLocation;
        //Run as Administrator.
        _ret.StartInfo.Verb = "runas";
        //Window = normal
        _ret.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
        _ret.StartInfo.CreateNoWindow = false;

        _ret.Start();
        return _ret;
    }

我在任务管理器中看到它。它工作但我看不到窗口。

(如果我看不到这个,那么我可以改变父母并看到它)我试试这个: 创建新的MidiChildWindow项目并:

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    private void GetListeners()
    {
        Process[] Memory = Process.GetProcesses();

        foreach (Process _prc in Memory)
        {
            if (_prc.ProcessName == "MyRunnedApplication")
            {
                SetParent(_prc.MainWindowHandle, this.Handle);
                ShowWindow(_prc.MainWindowHandle, 1);
            }
        }
    }

但它不起作用。 运行我的应用程序是Windows服务的孩子,我无法更改它。

我怎么看? (Sory我的英语不好)

0 个答案:

没有答案