Boris Raznikov
Boris Raznikov

Reputation: 2453

starting application and not see the console

I have an application (in .NET) and I want to start it on windows OS by a script and not see the console of it (will be hidden).
How can I do that ?

Spasiba

Upvotes: 0

Views: 56

Answers (2)

ChrisBD
ChrisBD

Reputation: 9209

You could run it as part of a service, but this would require it to have self installation code or be installed manually.

Another way is to write a Windows Forms application, but without the form and do the following:

using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            string ApplicationPath = @"c:\consoleapplication.exe";

            // Create a new process object
            Process ProcessObj = new Process();

            // StartInfo contains the startup information of
            // the new process
            ProcessObj.StartInfo.FileName = ApplicationPath;



                // These two optional flags ensure that no DOS window
                // appears
                ProcessObj.StartInfo.UseShellExecute = false;
                ProcessObj.StartInfo.CreateNoWindow = true;

                // If this option is set the DOS window appears again :-/
                // ProcessObj.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                // This ensures that you get the output from the DOS application
                ProcessObj.StartInfo.RedirectStandardOutput = true;

                // Start the process
                ProcessObj.Start();

                // Wait that the process exits
                ProcessObj.WaitForExit();

            }
        }
    }

You can then call this application with your script.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613053

Whatever ultimately calls CreateProcess needs to pass the CREATE_NO_WINDOW process creation flag.

The process is a console application that is being run without a console window. Therefore, the console handle for the application is not set.

Exactly how best to achieve that from a script would depend on what script language you are using.

Upvotes: 1

Related Questions