是否有可能假冒Windows控制台API? [英] Is it possible to fake windows console api?

查看:124
本文介绍了是否有可能假冒Windows控制台API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写在C#中的SSH服务器,我想这会是整齐挂钩的PowerShell作为外壳。我试过2种方法得到这个正常工作,但都是远远不够完善。以下是我已经试过:

I've written a ssh server in c# and I thought it'd be neat to hook up powershell as a shell. I've tried 2 methods to get this to work properly but both are far from perfect. Here's what I've tried:


  1. 启动powershell.exe并重定向它的STD(输入/输出)。这不
    工作做好,因为powershell.exe检测到它重定向,改变
    它的行为。更重要的是,它预计在stdid输入数据,而不是
    的命令。因此,使用控制台API来读取命令。

  2. 在包装应用程序主机的PowerShell。这有
    能够提供一个控制台实施的PowerShell(通过
    的PSHostRawUserInterface)的优势。这工作得更好,但你仍然可以调用
    命令(主要是真正的控制台应用程序),如... |更多,即希望
    才能够使用控制台的API,随后试着从阅读包装过程中的
    控制台。

所以我想做的是有一组函数替换该控制台应用程序使用常规控制台输入/输出功能,这样我就可以处理它们。但是,这似乎相当激烈到的是一个糟糕的设计理念(IMO)的地步。

So what I'd like to do is have a set of functions replace the regular console input/output functions that console applications use, so I can handle them. But that seems rather drastic to the point of being a bad design idea (imo).

现在我在用发送相关按键操作控制台的想法本地/ PInvoke的功能,如WriteConsoleInput。我推测,有可能伪造控制台的方式。但我不明白我怎么会那么读在控制台上会发生什么。

Right now I am on the idea of manipulating the console by sending the relevant keys with native/Pinvoke functions like WriteConsoleInput. I gather that it might be possible to fake the console that way. But I don't see how I would then "read" what happens on the console.

另外请注意,这是一个服务,因此最好不要随便重生一个实际的控制台窗口,虽然也许在Windows会话0,不会显示出来,并没有关系。

Also keep in mind, it's a service, so preferably it shouldn't spawn an actual console window, although perhaps in windows session 0 that wouldn't show up and not matter.

推荐答案

您已经有了的PSSession 为此目的而进入-的PSSession cmdlet的。什么会使用PowerShell的SSH做的PSSession是不是做

You've got PSSession for this purpose and the Enter-PSSession CmdLet. What will your SSH with Powershell do that PSSession is not doing ?

但是,如果你想要做的,这里是一个解决方案内部消除书面方式什么:通过SSH 使用PowerShell的

But if you want to do that here is a solution whithout writting anything : Using PowerShell through SSH

编辑02/11/2011

Edited 02/11/2011

里面的PowerShell 提供了另一种方式来做到这一点书面方式内部消除任何东西(免费供个人使用)。

PowerShell inside provide another way to do it whithout writting anything (free for personal usage).

<一个HREF =http://msdn.microsoft.com/en-us/library/windows/desktop/ee706577%28v=VS.85%29.aspx相对=nofollow> Host03样品,可以或许提供基本的代码,你笏做的事情。

Host03 sample, can perhaps provide basic code to do what you wat to do.

这篇关于是否有可能假冒Windows控制台API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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