santhosh
santhosh

Reputation: 161

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.

Code:

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

Upvotes: 1

Views: 3534

Answers (2)

jgauffin
jgauffin

Reputation: 101150

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.

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.

At client side add a <div id="commandOutput"></div> and <input type="text" name="command" /><input type="submit" value="Execute command" />. Use jquery or similar to hook the button click event.

Use ajax to submit the form. Execute the command by writing it to the stdin in the Process object that is saved in the session variable. Read from standard out and return the result to the client which adds it to commandOutput div using jQuery or something else.

That should do it. Do note that anyone with access can do anything with your server.

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1062780

asp.net runs at the server. 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 (i.e. don't do that).

Short answer: you cannot do this. No browser would (or should... I'll make allowances for IE ;p) allow this. The client OS need not even support a command prompt, nor .NET; and even if it did, very few browsers will let you spawn a process.

Upvotes: 5

Related Questions