[英]Write input to console using C
Let's say I am changing the password of a user, 假设我要更改用户密码,
#include <stdio.h>
#include <stdlib.h>
int main() {
system("net user myUsername *");
return 0;
}
and when run this program, I get back 当我运行这个程序时,我回来了
Type a password for the user:
How do I write to the console with a function without manually typing on to the keyboard? 如何在不手动输入键盘的情况下使用功能写入控制台? Is there some function like
有没有像
writeConsoleWindow("myPass");
submitConsole();
Use CreateProcess()
to launch cmd.exe
(which is what system()
does) with a redirected STDIN handle, then you can write data to cmd
in your code. 使用
CreateProcess()
启动具有重定向的STDIN句柄的cmd.exe
( system()
操作),然后可以在代码中将数据写入cmd
。 See Creating a Child Process with Redirected Input and Output . 请参见使用重定向的输入和输出创建子进程 。
However, in the specific case of net user
commands, you should be using functions like NetUserGetInfo()
, NetUserSetInfo()
, NetUserChangePassword()
, etc instead. 但是,在
net user
命令的特定情况下,应改用NetUserGetInfo()
, NetUserSetInfo()
, NetUserChangePassword()
等函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.