2

I want to run an exe on client system from my c# asp.net website. When I use Process.Start() it throws an error:

The requested operation requires elevation.

How do I set permissions to run that exe?

Tim Lloyd
  • 37,954
  • 10
  • 100
  • 130
Ashish Rathore
  • 2,546
  • 9
  • 55
  • 91
  • 2
    Then you're going to have to get the clients to download your executable and execute it willingly. – Cᴏʀʏ Aug 26 '11 at 12:42

4 Answers4

7

You can't spawn processes on the client machine from server-side code.

When you use Process.Start in server-side code, it is attempting to execute the process there, on the server where the website is hosted. If you wanted to create processes on the clients computer then you would need to expose a download for them (and not in employing subterfuge, like malign sites might do to install software - supply it gracefully, and normally (and with permission)), or a Silverlight application or something along those lines.

The bottom line is that the code you want to execute (even if that is just to spawn a process) must reside on the client, and be executed there.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • 9
    But, viruses do this all the time! ;) – Yuck Aug 26 '11 at 12:40
  • 1
    Virsues still need to be downloaded – Todd Moses Sep 12 '12 at 04:09
  • @ToddMoses or distributed on CD, DVD, USB, or something. The point is _viruses need to be on the client machine to execute code there_, in this context, yes, that generally means being downloaded, as touched on in my answer. What's your point? – Grant Thomas Sep 12 '12 at 17:04
4

You can't run an application from a web server like that. You will have to have the user download the application by supplying the EXE, a setup file or using ClickOnce.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
2

Or you can develop an ActiveX control that you can have the browser automatically download from a Trusted Internet Zone.

Once downloaded, proper signing with a certificate (signed from the trusted (corporate) root certificate) will avoid the user getting a prompt to ask whether he wishes to allow the ActiveX control to install/be activated -

The ActiveX control can subsequently do anything the interactively logged on user could. This means that to actually install a program you'd need to elevate (UAC on Vista+); But if the goal was just to run a standalone executable, you should be good to go.

This all assumes white-hat purposes in a (larger) corporate setting, because it relies on PKI infrastructure and central browser policies, to name just two.**

This would, really, lead to some excellent questions on serverfault or superuser

sehe
  • 374,641
  • 47
  • 450
  • 633
  • This idea would work given the right environment, although I have a feeling the OP is not prepared to write an entire ActiveX control to implement this feature. Also it is not clear whether the push functionality you mention is even necessary. +1 regardless – pseudocoder Aug 26 '11 at 14:11
  • I am new for this so guide me how to make ActiveX control in c# to call an exe installed on client machine. – Ashish Rathore Aug 29 '11 at 05:54
  • @ashish: That question is certainly too broad to answer in a comment; You could start here: http://dotnetslackers.com/articles/csharp/WritingAnActiveXControlInCSharp.aspx, also [here](http://stackoverflow.com/questions/3478907/whats-the-difference-between-an-activex-control-and-an-activex-object), [here](http://stackoverflow.com/questions/2062794/how-to-use-activex-with-asp-net) and [by searching on SO](http://stackoverflow.com/search?q=activex+browser) – sehe Aug 29 '11 at 07:08
2

I noticed you said you wanted to run an exe file on the client, but you didn't say explicitly that the exe is on the server and you want to push it to the client. Everyone seems to be assuming that is the case.

You CAN accomplish this fairly easily with a small JavaScript if you have a few prerequisites:

  1. The executable is already present on the client machine.
  2. All of your clients are running IE
  3. You can enforce a policy to put your site in the Intranet or Trusted Sites zone.

So basically this means it's a corporate intranet application. I am assuming this is probably the case since, well, if you were expecting to do this with a public app, I would be surprised.

For the script to accomplish this, please see my answer to this question:

How can I get a program on a client machine to run from an ASP.NET page?

Community
  • 1
  • 1
pseudocoder
  • 4,314
  • 2
  • 25
  • 40