1

I m trying to open Notepad, Calculator in button click in asp.net with code behind C#. I tried with the code

 System.Diagnostics.Process.Start("c:\\windows\\system32\\notepad.exe");

this is working fine in local system but not working in the Server. I even tried with the javascript

function executeCommands(inputparms)
{
alert('ff');
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Winnt\\Notepad.exe";
if (inputparms != "")
{
    var commandParms = document.form1.filename.value;
}

oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
}

even this is not working out. Can you please suggest me in on how to open the notepad application in the client end with out disturbing server notepad.

Fairy_G
  • 407
  • 3
  • 12
  • 23

6 Answers6

5

This can't be done. Imagine the security mess we'd be in if a web-page could run arbitrary programs on a client machine. Oh wait... ;-)

Andrew Cooper
  • 32,176
  • 5
  • 81
  • 116
  • can you give some more details regarding this plz. – Fairy_G Apr 19 '11 at 06:30
  • m dont have knowledge in arbitrary programs, so how to process with it. – Fairy_G Apr 19 '11 at 06:55
  • @Fairy_G: Arbitrary just means "anything you can think of". If a web-page was able to run any program that the web-page designer wanted to run on the client machine then that would be really bad for security. – Andrew Cooper Apr 19 '11 at 06:58
2

This is not possible (in general, though you could possibly get around with with various applets and browser plugins). In fact, I would be quite mortified if any web page could execute an arbitrary program on my computer.

1

You cannot do this. ASP.NET runs on the server and you cannot run programs on the client computer. The ActiveX object you have shown should work but only in IE and only after the user explicitly authorizes the execution of it. Also the location of notepad.exe might differ depending on the client (could be c:\windows, c:\winnt, ... and some clients running for example on Linux or MacOS don't have such executable)

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • can we open server's Notepad or else is it possible through flash? I really need some solution to open the notepad on a image click event. it ok whether its server's notepad or some sort. please. – Fairy_G Apr 19 '11 at 06:14
  • @Fairy_G, yes you can open server notepad using `Process.Start` but because ASP.NET runs under an account which doesn't even have an associated GUI don't expect to see it anywhere. It might appear in the list of running processes on the server but that's all. As far as Flash is concerned you cannot run executables on the client. – Darin Dimitrov Apr 19 '11 at 06:15
  • Thank you so much. but is there any other way to make this task done. – Fairy_G Apr 19 '11 at 06:21
  • @Fairy_G, ActiveX is probably one way of going but as I said in my answer it works only in IE and users must authorize it. You understand that running executables on client computer from a web site represents a huge security issue and it is not allowed. – Darin Dimitrov Apr 19 '11 at 06:25
1

What you are trying to achieve is not possible because of the nature of application in case of ASP.Net. The application will execute on server and will only send client side HTML to client. Even if your code is syntatically correct, it would open up the utilities on server itself.

Subhash Dike
  • 1,836
  • 1
  • 22
  • 37
-2

This Can be possible by using below code on click of server button or Link. System.Diagnostics.Process.Start("notepad.exe");

  • This will run Notepad on the server, not on the client machine which I suspect is what the questioner actually wants. As all the other answers have stated, running programs like this from a browser is not possible (unless you've found a serious security hole in the browser). – Spudley Apr 19 '12 at 18:02
-2
System.Diagnostics.Process.Start("C:\Windows\System32\calc.exe")

Works fine, though you may have to adjust settings on your browser. Be sure calc.exe is in the directory.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220