I run an EXE program from a Windows Service but I can't see form C#?

155 views Asked by At

I run another program from Windows Service

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

I see it in Task Manager. it is working but I can't see window.

(If I can not see this then I can change Parent and see it)I try this: Create new MidiChildWindow project and:

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

but its not work. Runned my application is child the Windows service and I can not change it.

How I see it? (Sory my bad english)

0

There are 0 answers