Adminstrator-running-fallback-patch

A few months ago, in the readme, we changed the `Set-Execution` policy to a process scoped one to avoid users exposing their machine.

That induces a new problem.
When we start the script without administrator rights, but with the `Set-Executionpolicy` scoped to `Process`, the script restarts itself with elevated rights but in the previously set execution policy (likely `RemoteSigned`).

This patch passes :
- NoProfile 
- ExecutionPolicy Bypass 
- NoExit
- File

To the newly created process.
This commit is contained in:
Old Character 2025-11-04 20:08:02 +01:00 committed by GitHub
parent 768c476b4d
commit c29e24df5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -90,7 +90,7 @@ if (! $myWindowsPrincipal.IsInRole($adminRole))
{
Write-Output "Restarting Tiny11 image creator as admin in a new window, you can close this one."
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
$newProcess.Arguments = "-NoProfile -ExecutionPolicy Bypass -NoExit -File `"$($myInvocation.MyCommand.Definition)`"";
$newProcess.Verb = "runas";
[System.Diagnostics.Process]::Start($newProcess);
exit
@ -533,3 +533,4 @@ Stop-Transcript
exit