majohn-r / mp3repair

An MP3 file repair command-line utility
MIT License
0 stars 0 forks source link

Run with elevated permissions when possible #148

Closed majohn-r closed 8 months ago

majohn-r commented 8 months ago

The mp3 program has a couple of problems when running with an ordinary user's permissions:

  1. The resetDatabase command cannot stop the Windows Music Service.
  2. The latest.log symbolic link is not created.

Both these problems go away when executing as an administrator.

The thinking here is to run with elevated permissions routinely, However, there is a gotcha: if the original command line invocation has stdout or stderr redirected to a file or pipe, that redirection cannot be captured and re-used in the new windows shell. Therefore, the logic to detect that the program needs to be re-executed with elevated permissions should also detect whether stdout or stderr are not writing to a terminal, and if that's the case for either one, do not run with elevated permissions.

Finally, there needs to be a mechanism to externally disable/enable the transition: an environment variable (suggestion: _MP3_RUNS_ASADMIN, set to true or false) that, if not found, defaults to true.