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..

santhosh
  • 11
  • 1
  • 2

3 Answers3

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);
Sergey K
  • 4,071
  • 2
  • 23
  • 34
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).

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367
  • +1 nice answer.. can you give a link on how to do this Via ActiveX control.. I'm really curios about it. – Shekhar_Pro Apr 05 '11 at 09:36
  • 1
    @Shekhar See [Create ActiveX in .NET Step by Step (Codeplex)](http://www.codeproject.com/KB/cs/CreateActiveXDotNet.aspx) 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. – Justin Apr 05 '11 at 10:55
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.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
  • 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... – santhosh Apr 05 '11 at 06:06
  • Should the command prompt execute on the client or on the server? – Lasse V. Karlsen Apr 05 '11 at 06:07
  • 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. – Shekhar_Pro Apr 05 '11 at 06:09