Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 587961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:16:03+00:00 2026-05-13T15:16:03+00:00

I need to automate an command line application. It asks the user to enter

  • 0

I need to automate an command line application. It asks the user to enter a password. All my approches to send the password via STDIN failed. Now I am trying to do this with an wrapper-programm using .NET.

I am starting the application creating a new process, setting the StartInfo-properties and then start the process:

Dim app_path As String
Dim app_args As String
Dim myProcess As Process = New Process()
myProcess.StartInfo.FileName = app_path
myProcess.StartInfo.Arguments = app_args
myProcess.StartInfo.UseShellExecute = False
myProcess.Start()

I did try to use the StartInfo.RedirectStandardInput Property but with no success.

Now I came accross the WriteConsoleInput function from the kernel32.dll that I included like this:

Declare Function WriteConsoleInput Lib "kernel32.dll" Alias "WriteConsoleInputA" (ByVal hConsoleInput As Integer, ByVal lpBuffer As String, ByVal nNumberOfCharsToWrite As Integer, ByRef lpNumberOfCharsWritten As Integer) As Boolean

I can get the handle of the process via the myProcess.Handle property. But sending input to the input-buffer using this way was also not possible.

I found those questions but they did not help:

  • How do I write ‘PAGE DOWN’ into the console input buffer? (1475353)

  • Java – passing input into external C/C++ application (1421273)

  • Controlling a Windows Console App w/ stdin pipe (723424)

Using StraceNtX.exe I got this output for the moment the app is waiting for input:

[T4024] GetConsoleMode(f, 12d35c, 12d3af, 77bff894, ...) = 1
[T4024] SetConsoleMode(f, 0, 12d3af, 77bff894, ...) = 1
[T4024] ReadConsoleInputA(f, 12d348, 1, 12d360, ...) = 1

Can anyone tell me, what else to try or how to do the above the right way?
Thanks!


Based on Tim Robinsons answere I’ve got this code now, but it does not work:

myProcess = New Process()
myProcess.StartInfo.FileName = app_path
myProcess.StartInfo.Arguments = app_args
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myProcess.StartInfo.UseShellExecute = False
myProcess.Start()
' Wait for process requesting passwort input
System.Threading.Thread.Sleep(3000)
Dim len As Integer
len = 0
Dim handle As Integer
handle = GetStdHandle(STD_INPUT_HANDLE)
WriteConsoleInput(handle, "Test", 4, len)

My programm is an commandline application that should act as an wrapper.

The input is send but in a way that it is not typed into the password field but that below the password field a new promt is shown (without even showing the input).

Tim, can you give me an example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:16:04+00:00Added an answer on May 13, 2026 at 3:16 pm

    Sorry for my late reply, been very busy.

    Here is an full code example, stripped down from my code. I hope I did not delete something crucial.

    Private Sub runWaitInput(ByVal exe As String, ByVal parameter As String, ByVal trigger As String, ByVal input As String)
        ' runs an process, waits for a certain string in stdout and then enters text '
        Dim proc As Process
        Dim stdOut As StreamReader
        Dim ch As Int32
        Dim buffer As String = ""
        Dim InputRecords(0) As KeyEventStruct
    
        ' create process '
        proc = New Process()
        proc.StartInfo.FileName = exe
        proc.StartInfo.Arguments = parameter
        proc.StartInfo.UseShellExecute = False
        proc.StartInfo.RedirectStandardOutput = True
        proc.Start()
    
        ' redirect stdOut '
        stdOut = proc.StandardOutput
        While Not proc.HasExited
            ' read character '
            ch = stdOut.Read()
            Console.Write(Convert.ToChar(ch))
            buffer = buffer & Convert.ToChar(ch)
            ' read output and check for trigger-text '
            If buffer.LastIndexOf(trigger) <> -1 Then
                buffer = ""
                InputRecords(0) = New KeyEventStruct
                InputRecords = generateInputRecord(input & Convert.ToChar(13))
                WriteConsoleInput(STD_INPUT_HANDLE, InputRecords, InputRecords.Count(), New Integer)
            End If
        End While
        Console.Write(stdOut.ReadToEnd())
    End Sub
    
    Function generateInputRecord(ByVal str As String) As KeyEventStruct()
        Dim ret(str.Count() - 1) As KeyEventStruct
        For i = 0 To str.Count - 1 Step 1
            With ret(i)
                .EventType = 1
                .bKeyDown = True
                .uChar.AsciiChar = Convert.ToInt32(str(i))
                .dwControlKeyState = 0
                .wRepeatCount = 1
                .wVirtualKeyCode = 0
                .wVirtualScanCode = 0
            End With
        Next
        Return ret
    End Function
    

    It uses the following module:

    Imports System.Runtime.InteropServices
    
    Module ConsoleUtils
    
        <Flags()> Public Enum ControlKeyState As Integer
            RightAltPressed = &H1
            LeftAltPressed = &H2
            RightCtrlPressed = &H4
            LeftCtrlPressed = &H8
            ShiftPressed = &H10
            NumLockOn = &H20
            ScrollLockOn = &H40
            CapsLockOn = &H80
            EnhancedKey = &H100
        End Enum
    
        <StructLayout(LayoutKind.Explicit)> Public Structure CHAR_UNION
            <FieldOffset(0)> Public UnicodeChar As Short
            <FieldOffset(0)> Public AsciiChar As Byte
        End Structure
    
        <DllImport("kernel32", EntryPoint:="WriteConsoleInputA", CharSet:=CharSet.Auto, SetLastError:=True, ThrowOnUnmappablechar:=True)> _
            Public Function WriteConsoleInput( _
                ByVal hConsoleInput As IntPtr, _
                ByVal lpBuffer() As KeyEventStruct, _
                ByVal nLength As Integer, _
                ByRef lpNumberOfEventsWritten As Integer _
            ) As Boolean
        End Function
    
        <DllImport("KERNEL32.DLL", EntryPoint:="GetStdHandle", SetLastError:=False, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
            Public Function GetStdHandle( _
                ByVal nStdHandle As Integer _
            ) As Integer
        End Function
    
        <StructLayout(LayoutKind.Sequential)> Public Structure KeyEventStruct
            Public EventType As Short
            <MarshalAs(UnmanagedType.Bool)> Public bKeyDown As Boolean
            Public wRepeatCount As Short
            Public wVirtualKeyCode As Short
            Public wVirtualScanCode As Short
            Public uChar As CHAR_UNION
            Public dwControlKeyState As ControlKeyState
        End Structure
    
        Public ReadOnly STD_OUTPUT_HANDLE As IntPtr = New IntPtr(GetStdHandle(-11))
        Public ReadOnly STD_INPUT_HANDLE As IntPtr = New IntPtr(GetStdHandle(-10))
        Public ReadOnly STD_ERROR_HANDLE As IntPtr = New IntPtr(GetStdHandle(-12))
    
    End Module
    

    With this function you can start the process and wait for a line of output (i.e. “password:”). Then the function will enter the provided text followed by an return.

    I hope this helps!

    Regards
    sc911

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 300k
  • Answers 300k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer i'd recommend SSL instead of implementing some encryption algorithm yourself… May 13, 2026 at 8:04 pm
  • Editorial Team
    Editorial Team added an answer Unit testing only requires "cut-planes" or boundaries at which testing… May 13, 2026 at 8:04 pm
  • Editorial Team
    Editorial Team added an answer You are giving your anchor tag around the IMG a… May 13, 2026 at 8:04 pm

Related Questions

I am trying to automate VC++ build via an addIn written using VB.NEt so
I have a Delphi application that has many dependencies, and it would be difficult
I have a run mode in my CGI::Application web-app that I would like to
I know that some companies allow you to install their products on build machines
My automated build process uses a command-line to build something like this: devenv.exe myproj.sln

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.