Control another program via C#

Noah Aas 985 Reputation points
2025-04-06T14:40:55.4333333+00:00

Hello!

Is it possible to open another program (C++) via C#?

Preferably minimized or not visible. Similar to a service. Is it possible to close another program (C++) via C#?

The background is.

// So far.
//    C++ application is running
            C++ -----PLC
// New 
//   An extension that is controlled via C#.
     C# ---- C++ -----PLC
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,428 questions
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 44,755 Reputation points MVP
    2025-04-06T14:47:32.5333333+00:00

    Yep, it is possible to start and close a C++ application from C#—even if you want it minimized or hidden, just like a background service. Based on your structure:

    C# ---- C++ ----- PLC
    

    your C# app acts like a controller or manager. It launches the C++ process (which talks to the PLC), possibly passing in arguments, monitors its health, and stops it when needed.

    1. Starting a C++ application via C# (hidden or minimized)

    You can use the System.Diagnostics.Process class in C# to start the C++ executable.

    Example (minimized):

    startInfo.WindowStyle = ProcessWindowStyle.Minimized;
    

    Example (hidden):

    using System.Diagnostics;
    
    Process cppProcess = Process_Start(startInfo);
    

    2. Closing the C++ application from C#

    If you keep a reference to the Process object (e.g., cppProcess), you can close it directly:

    Close by process object:

    cppProcess.Kill(); // Forcefully kills the process
    cppProcess.WaitForExit(); // Optional: Waits until it fully exits
    

    You can also find the target app by process name:

    foreach (var process in Process.GetProcessesByName("YourCppApp")) {
        process.Kill();
    }
    

    Btw. make sure the name does not include .exe in GetProcessesByName—just "YourCppApp".*


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.