当cmd以管理员身份运行时,如何将输入发送到cmd? [英] How to send input to cmd when cmd is running as administrator?

查看:68
本文介绍了当cmd以管理员身份运行时,如何将输入发送到cmd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个将键盘输入发送到 cmd.exe 的应用程序.当以普通用户身份运行 cmd 时,此方法有效,但以管理员身份运行 cmd 时,此方法将失败.

I created an application that sends keyboard input to cmd.exe. This works when running cmd as a normal user but fails when cmd is run as Administrator.

这是我的代码:

Var
   Wnd:hwnd;
begin
   wnd:=FindWindow('ConsoleWindowClass',0);
   if wnd <> 0 then
    begin
      setforegroundWindow(wnd);
      keybd_event(Ord('A'),0,0,0);
    end;
end;

请注意, ConsoleWindowClass cmd 的类名.

当以管理员身份运行 cmd 时,如何将输入发送到 cmd ?

How can I send input to cmd when cmd is running as administrator?

推荐答案

当cmd以管理员身份运行时,如何在cmd中键入此代码?

How can I type with this code inside cmd when cmd is runing as administrator?

您不能.此行为是设计使然.与进程相比,cmd进程以更高的完整性级别运行.解决此问题的唯一方法是安排伪造输入的过程也以管理员身份运行.

You cannot. This behaviour is by design. The cmd process runs with a higher integrity level than your process. Your only way to overcome this is to arrange that the process that fakes input also runs as administrator.

这篇关于当cmd以管理员身份运行时,如何将输入发送到cmd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆