none
Suppress console key input from function WriteConsoleInput

    Question

  • Hi

    I am working on an MFC application that executes a command on powershell console.
    The exe itself is invoked from powershell console.
    The exe attaches to the parent console and writes a command on the console.
    subsequently that command gets executed on the powershell console.
    This exe uses function WriteConsoleInput to write to the console

    Example run
    ==============
    PowerCLI C:\TVME\TestSignedExe> .\tdc.deploy.exe .\Properties\common.IT.properties.json .\Properties\node.IT.properties.json
    PowerCLI C:\TVME\TestSignedExe> iex ([System.Text.Encoding]::UNICODE.GetString((gp -path ([Environment]::GetEnvironmentVaria
    Checking Power-Shell Version.....

    In the above snippet tdc.deploy.exe is the exe invoked from powershell console and
    iex.... is the command that is executed on the console.

    I am trying at different ways to suppress the command iex.. from getting displayed on the console.
    I trying to execute the command without displaying it on the console.

    Please let me know if there are any ways to do it.
    Do I need to ask this question to the Powershell Team.
    Also please let me know if there are any other methods to execute a command on the console from an exe.

    Thanks
    Srikanth










    Monday, February 5, 2018 6:39 AM

All replies

  • Hi Doosa Srikanth,

    thanks for posting here.

    >>I am trying at different ways to suppress the command iex.. from getting displayed on the console.
    I trying to execute the command without displaying it on the console.

    Please provide more information about your requirement. How do you run the command? In PowerShell or with your application?

    The WriteConsoleInput function is used to write data directly to the console input buffer. If I don't misunderstand your issue, I suggest you use system method to run the command directly without showing it in your console.

    If you want to run the command silently with PowerShell,  you could post on this forum below.

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverpowershell

    Hope this could be help of you.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, February 6, 2018 8:12 AM
    Moderator
  • hI,

    My application is invoked in below steps

    User opens Powershell console and executes my exe.
    My exe is developed in VC++.
    It will just write a command to the same powershell console and executes it.
    Exe uses function WriteConsoleinput to write the input to power shell console.

    The issue is WriteCosnoleInput displays the input command on the console.
    I wanted to execute the command on the same powershell console without
    displaying the command to the user.

    Thanks
    Srikanth

    Thursday, February 8, 2018 7:08 AM
  • I don't think you read Baron's reply.  He told you how to do this.  Use the "system" routine from the C run-time, or use the CreateProcess API.

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Friday, February 9, 2018 10:58 PM