Process.start () does not properly start another application

1

Hello. I have a solution consisting of three applications. One is a Windows service ( BoardService.exe ). Another is a Windows Forms application that opens a splash screen and creates an icon in the Windows clock tray ( BoardPlayer.exe ). The third application is BoardMonitor.exe (console application) whose function is to start the windows service (BoardService.exe) if it stops and start BoardPlayer.exe if it is closed by the user. The idea is to do this without a command line window being displayed.

For this, I created a scheduled task for windows that runs every 3 minutes and calls the BoardMonitor.exe application.

Now comes my problem: By running the BoardMonitor.exe application manually, the BoardPlayer.exe application starts correctly, but when run through the scheduled task, the BoardPlayer.exe application appears in the Windows Task Manager, but it does not open the screens and does not appear on the clock tray. Look at the application code BoardMonitor.exe:

namespace BoardMonitor
{
    class Program
    {
        [DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);

        static void Main(string[] args)
        {
            try
            {
                // Verifica se o aplicativo BoardPlayer.exe está executando
                Process processo = Process.GetProcessesByName("BoardPlayer").FirstOrDefault();

                if (processo == null)
                {
                    using (Process p = new Process())
                    {
                        // Todos os aplicativos estão na mesma pasta                            
                        p.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BoardPlayer.exe");
                        p.Start();

                        SetForegroundWindow(p.MainWindowHandle);
                    }

                    Log.RegistraMensagem("Processo BoardPlayer.exe chamado pelo BoardMonitor.exe", TipoEvento.Alerta);
                }
            }
            catch (Exception ex)
            {
                Log.RegistraMensagem("Erro ao verificar se o aplicativo BoardPlayer.exe está rodando." + ex.Message, TipoEvento.Erro);
            }

            // Trecho que inicia o serviço
        }
    }
}

I imagine the problem is when setting the properties of StartInfo, however, I do not know how to proceed. I already looked for what I could on the web and found several solutions but none of them helped me.

Thank you in advance for the help you have received.

    
asked by anonymous 13.03.2017 / 20:02

0 answers