3

I am trying to run my c# exe as an system account. How can I do that. I've tried <requestedExecutionlevel level="requireAdministrator"> and <requestedExecutionlevel level="requireSystem"> The administrator is working but the second one is not working.

Please help me how can I do this.

Digvijay Rathore
  • 348
  • 6
  • 17
  • This thread may help you out as well: http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7 – mwilson Dec 10 '15 at 06:24
  • @mwilson Yes I've tried it and its working. But I want it to be run using SYSTEM. Like if I go to taskbar details it should show SYSTEM as username of exe. – Digvijay Rathore Dec 10 '15 at 06:29
  • Out of curiosity, what are you trying to do that your executable requires SYSTEM privileges instead of just Administrator privileges? – Scott Chamberlain Dec 10 '15 at 06:53
  • @ScottChamberlain I need to create an exe using c# that will run as a system account for example armsvc.exe of adobe runs as a system account. – Digvijay Rathore Dec 10 '15 at 13:23
  • Your last comment did not answer my question, your answer to "*Why do you need to run as SYSTEM?*" was "*I need to create an exe using c# that will run as a system account*" then you gave me a example of some other app that does it. Also `armsvc.exe` is running as a windows service, it is not a program you can just double click on and run. Are you writing a windows service? If you are not writing a service **why** does **your program** need to run as SYSTEM? – Scott Chamberlain Dec 10 '15 at 17:44
  • You just made up `requireSystem` didn't you – David Heffernan Dec 19 '15 at 09:03
  • @DavidHeffernan No I didn't. Just go to your service installer and set account type as Local system. now start your service simply – Digvijay Rathore Dec 19 '15 at 09:14
  • No. You made it up. Where is that documented as a `requestedExecutionlevel`? – David Heffernan Dec 19 '15 at 09:47
  • @DavidHeffernan Not got you concern please be specific – Digvijay Rathore Dec 19 '15 at 11:34
  • Never mind. It's all there if you want it. – David Heffernan Dec 19 '15 at 11:58

3 Answers3

7

To the best of my knowledge you can not force your app to run as SYSTEM. Either your app must be a service and the service is setup to run as System or you must use a tool like PsExec to launch your executable as system.

psexec.exe -i -s YourProgram.exe

When using requestedExecutionlevel the only 3 valid options are

  • requireAdministrator - prompt for UAC always (even if the user is not an administrator).
  • asInvoker - never prompt for UAC.
  • highestAvailable - prompt for UAC if the user is a member of the Administrators group but do not prompt and run as a normal user if the user is not a member of the group.
Scott Chamberlain
  • 121,188
  • 31
  • 271
  • 414
2

It's not directly possible. There are hacky ways if you are an administrator (like getting the security token from an already running service or something), but I far from recommend using those.

The point of the SYSTEM account is precisely that: that it's only run directly by the system.

If you want an easy-hacky-way without third-party tools (like psexec), you could set up a ONEEVENT scheduled task (with schtasks, which is part of the OS), which can indeed run with the system account. This would still need two processes (although it could be the same exe with different command line parameters for the task and for setting it up), but it'd work.

Jcl
  • 26,466
  • 5
  • 58
  • 85
-2

Hi I've found the solution. If you really want your exe to be run as system account you need to create a windows service and start it as a local system account. you would be able to see an exe is running at task manager along with a system account user. That is what I needed to know.

Digvijay Rathore
  • 348
  • 6
  • 17