Ask the Expert

In ASP.NET, how can I open an MS-DOS window using a hyperlink?

I am working on ASP.NET and I would like to know how I can open an MS-DOS window by using a hyperlink. Can you tell/show me how to do this?
There are two sides to this question. You may want to execute a program from the command prompt on the server side, after a click in a hyperlink server control, or you may want to open the commmand prompt on the client side after the user clicks a link.

The first case may be achieved with the following code in the hyperlink's click event handler:

System.Diagnostics.Process.Start("cmd");

You can also use the ProcessStartInfo class in the same namespace to gain better control over the process execution, such as redirecting the standard input/output streams, waiting for completion, etc.

The second case is a matter of client-side scripting. I'm sure there are other ways of doing this, but one of them is using the Shell object from WSH (which must be installed on the client machine, of course):

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run("cmd.exe")

You will receive the usual warning about security and ActiveX execution.

This was first published in February 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: