1

Please try to help me.. How to open and write commands in Command Prompt using asp.net3.5,C#.net...

if i click a Button in my UI it should open the commaond Prompt and i want excute few commands there...

Thank you..

1
  • 1
    In the client side or server side? Commented Apr 5, 2011 at 6:03

3 Answers 3

2

Try to use this code you need to add the namespace

using System.Diagnostics;

 var processStartInfo = new ProcessStartInfo
                                   {
                                       Arguments = "ping google.com",
                                       FileName = "cmd"
                                   };

        Process process = Process.Start(processStartInfo);
Sign up to request clarification or add additional context in comments.

Comments

1

It sounds like you want to open the command prompt from a browsers on the client PC.

To do this you either need to:

  • Use an ActiveX control, which will require that the user approve the installation of the ActiveX control.
  • Use the WScript.Shell object which is very unlikely to be available (for security reasons) unless your site is in a "very trusted" zone.

I.e. you can't expect a normal user to allow this to happen - this is only really going to be useful on your own PC.

If this is OK then you can find an example of running an application from JavaScript using the WScript.Shell object here (this is the easiest of the two options).

2 Comments

+1 nice answer.. can you give a link on how to do this Via ActiveX control.. I'm really curios about it.
@Shekhar See Create ActiveX in .NET Step by Step (Codeplex) on how to create an ActiveX control in C# - you can then just use the .Net Process class. Its a lot more hassle for something this simple.
0

You said

if i click a Button in my UI

so do you mean on the client side from browser.. sorry that's not possible from any JavaScript Code. You can't start a process on clients system with any code running in Browser. Something should be installed as a Desktop app to do that.

3 Comments

what should i do now... client PC also windows...So if click my button from my web-application i want to open command prompt pls give me options i am hanged here...
Should the command prompt execute on the client or on the server?
A possible solution could be to create a Simple Desktop App or Windows Service and ask user to install it on his Client system.. IF you need to communicate with server then you can use HttpWebRequest and Response Classes to do th communication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.