sttz / install-unity

Script to install Unity 3D versions from the command line on macOS
MIT License
131 stars 25 forks source link

Add admin popup on Windows when running install-unity #33

Open ewilh opened 2 years ago

ewilh commented 2 years ago

Added app.manifest for admin privilege request. Running install-unity will now prompt user for admin credentials. The downside is that not all methods in install-unity require admin consent, but it will ask for it regardless. I haven't changed anything from the default app.manifest except on line 19 with the code: <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> There might be more changes needed in the app.manifest before it's ready for production.

I also added RuntimeIdentifiers so that I'm able to publish the app. I'm not quite sure how you're able to publish on Windows without this.

I noticed that Unity was firstly installed on the path Unity {major}.{minor}, and I don't necessarily like that approach. Most Unity users (and especially those who use this tool) will install multiple different Unity versions on {major}.{minor}. I recommend removing this both for Windows and Mac, but here I've only removed it for Windows.

major_minor

ewilh commented 2 years ago

Note that after the admin pop-up, a separate shell window with admin privileges will open. When the code is finished running, the admin shell window will close immediately, thus preventing the user from seeing the output. A solution is to add a "Press any key to exit" on Windows only. Something like this:

  public static int ExitAfterUserInput(int exitCode)
  {
      Console.WriteLine("Press any key to exit");
      Console.ReadLine();
      return exitCode;
  }