简体   繁体   English

如何从我的应用程序@Client端打开命令提示符

[英]How to open command prompt from my application @Client side

Please help me how to open command prompt from client side. 请帮助我如何从客户端打开命令提示符。 When i click on the button it should open command prompt. 当我单击按钮时,它应该打开命令提示符。 I tried in my PC and it's working in the development environment but when deploy in IIS its not opening. 我在PC上尝试过,它在开发环境中正常工作,但是在IIS中部署时无法打开。

Code: 码:

    var Processstartinfo = new ProcessStartInfo
    {           
        FileName = "cmd"
    };
    Process process = Process.Start(Processstartinfo);

asp.net runs at the server. asp.net在服务器上运行。 I suspect you are running in cassini locally, so your server desktop and client desktop are the same thing. 我怀疑您是在卡西尼本地运行的,因此您的服务器桌面和客户端桌面是同一件事。 What you are doing is opening a command prompt at the server ; 您正在做的是在服务器上打开命令提示符; which is an interesting DDOS attack surface if you think about it (ie don't do that). 如果您考虑一下的话,这是一个有趣的DDOS攻击面(即不要这样做)。

Short answer: you cannot do this . 简短的答案:您不能这样做 No browser would (or should... I'll make allowances for IE ;p) allow this. 没有浏览器会(或应该...我将为IE允许; p)允许这样做。 The client OS need not even support a command prompt, nor .NET; 客户端OS甚至不需要支持命令提示符,也不需要.NET。 and even if it did, very few browsers will let you spawn a process. 即使这样做,也很少有浏览器可以让您产生一个进程。

You need to create a fake command prompt to be able to do this. 您需要创建一个伪造的命令提示符才能执行此操作。 As Marc said, it introduces a huge security risk and I would never to it. 就像Marc所说的那样,它带来了巨大的安全风险,而我绝不会这样做。

To solve it you need to redirect standard input/output so that you can read/write to them. 要解决此问题,您需要重定向标准输入/输出,以便可以对其进行读取/写入。 Here is an example . 这是一个例子 Create the command process and save the Process object in a session variable. 创建命令流程,然后将Process对象保存在会话变量中。

At client side add a <div id="commandOutput"></div> and <input type="text" name="command" /><input type="submit" value="Execute command" /> . 在客户端添加<div id="commandOutput"></div><input type="text" name="command" /><input type="submit" value="Execute command" /> Use jquery or similar to hook the button click event. 使用jquery或类似的方法来钩住按钮单击事件。

Use ajax to submit the form. 使用ajax提交表单。 Execute the command by writing it to the stdin in the Process object that is saved in the session variable. 通过将命令写入保存在会话变量中的Process对象中的stdin来执行命令。 Read from standard out and return the result to the client which adds it to commandOutput div using jQuery or something else. 从标准输出读取并将结果返回给客户端,该客户端使用jQuery或其他方式将其添加到commandOutput div中。

That should do it. 那应该做。 Do note that anyone with access can do anything with your server. 请注意,具有访问权限的任何人都可以对您的服务器执行任何操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM