Process.start() does not start another application correctly

Asked

Viewed 226 times

1

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

So I created a scheduled windows job that runs every 3 minutes and calls the application Boardmonitor.exe.

Now comes my problem: Running the Boardmonitor.exe application manually, the Boardplayer.exe application starts correctly, but when run through the scheduled task, the application Boardplayer.exe now appears in the Windows Task Manager but it does not open the screens and does not appear in the clock tray. See 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 lies in defining Startinfo’s properties, but I don’t know how to proceed. I’ve searched what I can on the web and found several solutions but none of them helped me.

Thanks in advance for the help received.

  • I found the solution to the question problem on the link (https://social.msdn.microsoft.com/Forums/vstudio/en-US/0c0ca087-5e7b-4046-93cb-c7b3e48d0dfb/how-run-client-application-as-a-windows-service-in-c?forum=csharpgeneral).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.