从shell窗口获取输入命令 [英] Get input command from shell window

查看:132
本文介绍了从shell窗口获取输入命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图从shell Window获取输入命令(不是输出结果)。下面是场景。

我正在尝试使用C#获取此信息,但如果使用C#无法实现,则任何其他语言(如C / C ++)也将起作用。



1-用户在Shell Window中输入一些命令。

命令如dr / cd / mkdir等

Shell窗口,如命令提示符/ PowerShell

2-每当用户按下回车键时,捕获他执行的命令并记录下来。

3-我需要一个适用于所有shell窗口的一致方法。除了cmd和powershell之外,还有更多的外壳窗口。



我尝试过:



1-我尝试过使用键盘按键。使用键盘按下,我可以捕获关键细节,但用户可以使用一些快捷键。所以这不会起作用



2 - 试图从Window标题中获取数据。这适用于Command提示但不适用于powershell。



3-尝试Window API,如getWindowText,但它给出了窗口标题。我想,有数千个WinAPI。如果有人可以缩小对WinAPI方法的一些建议。那也行不错



请帮助!!

Hi,

I am trying to get input command from shell Window (not output result). Below is the scenario.
I am trying to get this info using C#, but if it is not possible with C#, any other language like C/C++ will also work.

1- User enter some command in Shell Window.
Command like dr/cd/mkdir etc
Shell window like Command prompt/ PowerShell
2- Whenever user press enter, capture the command which he executed and log it.
3- I need a consistent approach which work on all shell window. There can be more shell windows apart from cmd and powershell.

What I have tried:

1- I tried using keyboard press. Using Keyboard press, I am able to capture key detail but user can use some shortcut keys. so this will not work

2-Trying to get data from Window title. This work for Command prompt but not with powershell.

3- Tried Window API like "getWindowText" but it is giving window Title. I suppose ,there are thousand of WinAPI. If anyone can narrow down the give some suggestion on WinAPI methods. That will also work

Please help !!

推荐答案

这不可能。您无法知道其他应用程序(以及这些shell基本上只是应用程序)对输入做了什么。你所能做的就是全局跟踪键盘和鼠标事件。



但是那(以及你想要做的事情)是嗅探操作,这可能是辱骂(例如嗅探)帐户信息和密码)。因此,这里不应该有公共解决方案。





That is not posssible. You can't know what other applications (and these shells are basically just applications) do with there input. All you can do is tracking keyboard and mouse events globally.

But that (and what you are trying to do) are sniffing operations which might be abusive (e.g. for sniffing account information and passwords). Therefore, there should be no public solutions here.


Quote:

我正在尝试创建一种记录器。但是要注意记录器没有捕获敏感数据。

我可以假设,这是不可能的吗?

I am trying to create a type of recorder. But taking care that recorder is not capturing sensitive data.
So can i assume,it is not possible?



命令提示符和PowerShell正在记录历史已在内部,但我不知道如何以编程方式获取历史记录,我认为由于上述原因,这是不可能的。



在命令中提示窗口按F7。将打开一个窗口显示历史记录,您可以打开上下文菜单以选择全部并将其复制到剪贴板。



使用PowerShell使用Get-History [ ^ ]显示历史记录并选择将其保存到文件中。



因此您可能会尝试向这些窗口发送相应的击键(请参阅如何:在代码中模拟鼠标和键盘事件| Microsoft Docs [ ^ ])并从剪贴板r获取数据ESP。保存的文件。但我不确定这是否适用于那些shell提示应用程序。

[/ EDIT]


The command prompt and the PowerShell are recording the history already internally but I don't know of a way to get the history programmatically and I think that it is not possible due to the mentioned reasons.

In a command prompt window press F7. A window will be opened showing the history and you can open a context menu to select all and copy it to the clipboard.

With the PowerShell use Get-History[^] to show the history and optionally save it to file.

So you might try to send corresponding keystrokes to those windows (see How to: Simulate Mouse and Keyboard Events in Code | Microsoft Docs[^]) and get the data from the clipboard resp. the saved file. But I'm not sure if that works for those shell prompt applications.
[/EDIT]


这篇关于从shell窗口获取输入命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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