-2

I am trying to build a .NET wrapper around the 1Password CLI tool in order to manage our vaults from within our internal tools, however I can't seem to be able to send the input. It appears that it's not using the usual stdin for inputing the password. Is there a way to launch a process and send it keystrokes instead of using stdin?

The following does NOT work, the executable does NOT receive the input:

ProcessStartInfo processStartinfo = new ProcessStartInfo(_opPath, arguments)
{
    CreateNoWindow = true,
    UseShellExecute = false,
    RedirectStandardInput = true,
    RedirectStandardOutput = true,
    RedirectStandardError = true
};
Process process = Process.Start(processStartinfo);
process.StandardInput.WriteLine("password");
process.StandardInput.Flush();
2
  • What you're asking for sounds very unlikely. If you're redirecting StandardOutput you need to read it or your process will deadlock. Commented Feb 5, 2021 at 23:30
  • I can read StandardOutput and StandardError just fine, the problem is that even if I do read it, no matter what I send to StandardInput, the op.exe executable never receives it. Commented Feb 5, 2021 at 23:33

2 Answers 2

0

Perhaps try to set the StandardInputEncoding to System.Text.ASCIIEncoding (or other Encodings) and see if it works then?

PostThreadMessage

If all else fails maybe this will work for you. Consider investigating using the PostThreadMessage function. The password application will definitely have a message queue you can send the message to.

Once you have the threadId (Process.Threads) then send WM_Char messages to the password process and see if it processes them.

public const Int32 WM_CHAR = 0x0102;
public const Int32 WM_KEYDOWN = 0x0100;
public const Int32 WM_KEYUP = 0x0101;

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool PostThreadMessage(uint threadId, uint msg, IntPtr wParam, IntPtr lParam);
Sign up to request clarification or add additional context in comments.

Comments

0

Turns out that it was in line with what Dour mentioned, the caveit is that the order is very specific (at least in my case). Write to StandardInput, then read StandardOutput, then read StandardError. Any other order would cause a deadlock.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.