Hello

I have made a little program in C#. I am writting it in notepad and compiling via command prompt. But when i start that program there is console window and I dont know how to hide it.

Here is the code:

using System.Diagnostics;

class Program
{
    static void Main()
    {
	Process.Start("myfile.exe");
	System.Threading.Thread.Sleep(50000);
	Process.Start("http://myweb.com");
    }
}

sorry for my english

Can somebody write me the code please?

As per the example that gusano79 posted... here is the code linked in the MSDN page
that gusano79 also provided in his CreateNoWindow link.

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                // This code assumes the process you are starting will terminate itself. 
                // Given that is is started without a window so you cannot terminate it 
                // on the desktop, it must terminate itself or you can do it programmatically
                // from this application using the Kill method.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Hi
try this

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
using System.IO;
using System.Diagnostics;

namespace nms
{
    public class cls
    {
        [DllImport("user32.dll")]
        private static extern int ShowWindow(int Handle, int showState);

        [DllImport("kernel32.dll")]
        public static extern int GetConsoleWindow();


        static void Main(string[] args)
        {
            int win = GetConsoleWindow();
            ShowWindow(win,0);
            
            Process.Start("myfile.exe");
	    System.Threading.Thread.Sleep(50000);
	    Process.Start("http://myweb.com");
        }
    }
}

Chilaka Umesh

Thanks you very much.

can some one help me how can hide my command prompt in my progam.only want output don't want to show any window display.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Runtime.InteropServices;


namespace PortDataReceived
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort mySerialPort = new SerialPort("COM1");
            if (mySerialPort.IsOpen == true) mySerialPort.Close();
            mySerialPort.BaudRate = 2400;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.One;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;
            mySerialPort.Open();
         // Console.WriteLine("Press any key to continue...");

            Console.ReadLine();

            mySerialPort.ReadTimeout = 100;


            string indata = mySerialPort.ReadExisting();
            Console.WriteLine(indata);

            if (string.IsNullOrEmpty(indata))
            {
                StringBuilder builder = new StringBuilder();
                StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);
                sw.WriteLine(indata);
                sw.Close();

            }
            else
            {
                StringBuilder builder = new StringBuilder();

                for (int i = 0; i < indata.Length-8; i += 8)
                {

                    string section = indata.Substring(i, 8);

                    //int ascii = 0;
                    string ascii = "";
                    try
                    {
                        //ascii = Convert.ToInt32(section, 2);
                        ascii = section;
                        StreamWriter sw = new StreamWriter(@"c:\arjun.txt", true);

                        foreach (char c in section)
                        {
                            if (Char.IsLetterOrDigit(c))
                            {
                                builder.Append(c);
                            }
                        }

                        sw.WriteLine(builder.ToString());
                        sw.Close();
                        break;
                    }
                    catch(Exception e)

                    {

                        throw e;


                    }
                     // builder.Append((char)ascii);
                }


              //  Console.WriteLine(builder.ToString());
               // Console.WriteLine(indata);
                //Console.WriteLine("Data Received:");
                //Console.Write(indata);
               //  Console.ReadKey();
                mySerialPort.Close();

            }



        }
    }
    }