locked
Hide console input written using function WriteConsoleInputA RRS feed

  • Question

  • I had developed an executable in MFC Named tdc.deploy.ps1.exe. This exe writes commands to console input buffer using function WriteConsoleInputA. I had executed my exe tdc.deploy.ps1.exe on a powershell console and it writes command to the power shell console and it gets executed fine as below

    PowerCLI C:\MyFiles\2017\TVME\TVMEBinaryExecutable\tdc.deploy.ps1\tdc.deploy.ps1\Debug> .\tdc.deploy.ps1.exe

    PowerCLI C:\MyFiles\2017\TVME\TVMEBinaryExecutable\tdc.deploy.ps1\tdc.deploy.ps1\Debug> while ( -not ( $env = [environment]::getenvironmentvariable('tvme6120

    1714254831','user') )) {} ; iex ([system.text.encoding]::unicode.getstring((gp -path ($env)).tvme61201714254831))

    Checking Power-Shell Version....

    My question is can I hide the command written to the console and get it executed. That means user should not be able to see my command 

    while ( -not ( $env = [environment]::getenvironmentvariable('tvme6120

    1714254831','user') )) {} ; iex ([system.text.encoding]::unicode.getstring((gp -path ($env)).tvme61201714254831))

    But it should get executed.

    • Moved by Hart Wang Wednesday, June 7, 2017 2:57 AM
    Tuesday, June 6, 2017 7:08 PM

All replies

  • Hi,

    Thank you for posting here.

    Since your issue is related to Power shell issue, i will move the case to there.

    Best Regards,

    Hart


    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.

    Wednesday, June 7, 2017 2:50 AM
  • PowerShell CLI is not supported in this forum.  You will need to post in a forum for your application,


    \_(ツ)_/

    • Proposed as answer by Hello_2018 Wednesday, June 7, 2017 5:43 AM
    Wednesday, June 7, 2017 4:54 AM
  • Hi,

    >>My question is can I hide the command written to the console and get it executed. That means user should not be able to see my command 

    In powershell, you could make these commands as a parameter, e.g.:

    Invoke-Command -ComputerName (Get-Content Servers.txt) -FilePath C:\Scripts\Sample.ps1 -ArgumentList Process, Service

    https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/invoke-command?f=255&MSPPError=-2147217396

    Or, writing a function then pass these commands as parameters to it.

    function do-something
    {
        [void][system.reflection.assembly]::LoadWithPartialName('microsoft.visualbasic')
        #[cmdletbinding()]
     
            #[parameter(Mandatory=$true,HelpMessage='Need path')]
         [string]$path = [Microsoft.VisualBasic.Interaction]::inputbox('Pls enter afile path','File Path','c:\test.ps1')
        
    
        try{
           Microsoft.PowerShell.Management\Copy-Item -Path $path -Destination \\10.168.196.93\powershell-scripts -ErrorAction Stop
    
        }catch{
            $_.exception.message
        }
    }
    do-something -path "c:\share"

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, June 7, 2017 5:42 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Andy

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, June 8, 2017 10:05 AM
  • As you suggested I checked documentation of  Invoke-Command but that is not solving my issue.

    Let me describe my problem as below 

    User opens Powershell console and executes tdc.deploy.ps1.exe which is developed in VC++.
    tdc.deploy.ps1.exe writes one more powershell command to the Input buffer of Powershell and executes it.
    Execution is proper but the command written to Input buffer of Powershell gets displayed on the console.
    I wanted to hide this command on console while executing it.

    Please let me know if any more details are required.

    Thursday, June 8, 2017 10:44 AM
  • As you suggested I checked documentation of  Invoke-Command but that is not solving my issue.

    Let me describe my problem as below 

    User opens Powershell console and executes tdc.deploy.ps1.exe which is developed in VC++.
    tdc.deploy.ps1.exe writes one more powershell command to the Input buffer of Powershell and executes it.
    Execution is proper but the command written to Input buffer of Powershell gets displayed on the console.
    I wanted to hide this command on console while executing it.

    Please let me know if any more details are required.

    -RedirectStandardOutput
    Specifies a file. This cmdlet sends the output generated by the process to a file that you specify. Enter the path and file name. By default, the output is displayed in the console.

    Try using: start-process:

    https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/start-process

    Hope this helps.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Edited by Hello_2018 Friday, June 9, 2017 4:18 AM
    • Proposed as answer by Hello_2018 Tuesday, June 13, 2017 4:33 AM
    Friday, June 9, 2017 4:12 AM
  • Hi Andy,

    I want to hide the Input, not the Ouput.

    Thanks

    Srikanth

    Wednesday, June 14, 2017 2:12 PM
  • Hi Andy,

    I want to hide the Input, not the Ouput.

    Thanks

    Srikanth


    You need to contact the author of your custom EXE to get it to change the way it access PowerShell.

    \_(ツ)_/

    • Proposed as answer by Hello_2018 Thursday, June 15, 2017 1:45 AM
    Wednesday, June 14, 2017 6:34 PM
  • Hi Andy,

    I myself is the author of the custom EXE.

    I have developed this EXE in VC++.

    Please help me to hide console input written from the EXE.

    Thanks

    Srikanth

    Thursday, June 29, 2017 7:19 PM
  • Hi Andy,

    I myself is the author of the custom EXE.

    I have developed this EXE in VC++.

    Please help me to hide console input written from the EXE.

    Thanks

    Srikanth

    You cannot do it in PowerShell.  You have to change your program to work correctly with PowerShell.


    \_(ツ)_/

    • Proposed as answer by Hello_2018 Friday, July 7, 2017 4:22 AM
    Thursday, June 29, 2017 8:58 PM