Q

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

Dig deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

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:

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close