1

I am using Unity to build my game. I need the application to always run as administrator.

When I build my game, I right click on the exe that is produced and set 'Run this program as an administrator' on in the Compatibility > Settings section of the exe properties.

I can write an editor script (C#) that'll execute after a build has completed. So I was wondering if I could automate this step so that I do not forget to do it every time I build?

Nain
  • 1,204
  • 1
  • 12
  • 17
Prodigga
  • 1,457
  • 1
  • 22
  • 37
  • are you talking about doing something like [This](http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7) for Unity-Windows Application? – Umair M Aug 04 '15 at 05:54
  • Yes. I want the built exe to always launcht he 'run as administrator' dialogue. I can achieve this manually by right clicking on the exe, going to 'Compatibility' tab, and checking 'Run this program as an administrator' in the 'settings' section – Prodigga Aug 04 '15 at 06:00
  • I don't think that you can do this using post processing in Unity. You should contact Unity support to make sure if there is some other way around. – Umair M Aug 04 '15 at 06:06

2 Answers2

0

I'm not sure if this solves your issue. But you could add an "Application Manifest File" and configure:

 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

With this configuration the user gets always a UAC promt.

CodeTherapist
  • 2,776
  • 14
  • 24
0

Do not have a ready made solution but i can give you an idea:

Have a look at this, using this way you can check if your application is running as an administrator, if no, it starts another process with administrative privilege and you can later call:

Application.Quit();

to terminate the current instance.

Other than this you must have to wrap this code under platform dependent compilation.

I know it is not a best solution, but can fix this issue.

Hope it helps!

Community
  • 1
  • 1
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56