Hello ,

I have a .exe file written in C++. i have used;

Process.Start("E:\\cmdf.exe");

to execute the code from C#.

Now i need to ;

(1) hide the command prompt

(2) Then to find a way to stop the command prompt (as in closing the application)

How do i do this.

Dani AI

Generated

A concise follow-up for based on the existing answers: showed hiding a shell window and linked a Process.Start overview. For a console-built C++ exe the most reliable approach is to start the process without creating a console and give the launcher a way to stop it gracefully.

Start hidden and capture output by disabling shell execution and turning off window creation. This also allows redirecting standard streams if the C++ program writes to stdout/stderr.

var psi = new ProcessStartInfo
{
    FileName = @"E:\cmdf.exe",
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardOutput = true,
    RedirectStandardError = true
};

using (var proc = Process.Start(psi))
{
    // read output or keep proc reference to control shutdown
}

Stopping the process: for GUI apps, CloseMainWindow() requests a polite shutdown; for console apps that do not listen for window messages, CloseMainWindow() will not work and Kill() is the fallback (forceful). A common pattern is to ask for a graceful close, wait a short timeout, then kill if still running.

For truly graceful termination of a console C++ program, add a shutdown mechanism inside the exe (named event, pipe/socket, stdin marker, or a command-line “stop” mode). Advanced options include sending a console control event or using Windows job objects to manage child processes — these require native calls and careful handling. Note: CreateNoWindow only has effect when UseShellExecute is false, and wrapping the exe in cmd.exe is usually unnecessary.

Recommended Answers

All 2 Replies

I have never used Process.Start inside any of my applications before. But this is an interesting read, maybe it can be of use.

try this:

ProcessStartInfo ps = new ProcessStartInfo("cmd.exe");
            ps.WindowStyle = ProcessWindowStyle.Hidden; //will hide the process

            Process p = Process.Start(ps);

            p.WaitForExit(); //wait for process to complete
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.