Execute GUI process and its child processes as hidden

Background:
I have been trying to automate VNC viewer process to connect the server and check whether it is active or not and save it in file. There is a list of servers that needs to be checked. For that I downloaded UltraVncViewer for this, developed a program to execute VncViewer via commandline by providing host and password as cmd args.

Problem:
When the VncViewer connected, vncviewer window appears or when it is not connected, then a message box showing error pops up. How can start the process silently or in background hidden, so that I can work normally without popping that window.

Code I am using to start process. I need to make this work silently with hidden or no window. (I have used CreateNoWindow or Window Style hidden, but it is used for Console window, but I have GUI window. I have tried developing batch file which uses /B parameter to start process in background, but there is no way to provide commandline args dyanmically).

Code

Process p = new Process();
            // Start the child process.

            p.StartInfo.ErrorDialog = false;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            p.StartInfo.FileName = @"UltraVNCvncviewer.exe";
            //StartInfo.CreateNoWindow = true;
            //StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
            string pass = serverinfo.Password;
            if (pass == null)
            {
                p.StartInfo.Arguments = string.Format("-console -multi -nostatus -connect {0}"
                    , args);
            }
            else
            {
                p.StartInfo.Arguments = string.Format("-console -multi -nostatus -connect {0} -password {1}"
                    , args, pass);
            }

            string output = string.Empty;
            string s = string.Empty;

            p.Start();
          //wait for the process to start
           Thread.Sleep(4000);
         if(p.MainWindowTitle.ToLower() == "vncviewer message box")
            {
                p.Kill();
                return serverinfo.IsActive = false;
            }
            else
            {
                p.Kill();
                return serverinfo.IsActive = true;
            }

Any help?


Source: windows

Leave a Reply