FFmpeg: try to download wrapper with elevated privileges
authorAlexander Alekhin <alexander.alekhin@intel.com>
Tue, 2 Apr 2019 13:38:28 +0000 (16:38 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Tue, 2 Apr 2019 13:40:11 +0000 (16:40 +0300)
3rdparty/ffmpeg/ffmpeg-download.ps1.in

index e92ef45..999cd6f 100644 (file)
@@ -13,6 +13,22 @@ Write-Output ""
 
 if(![System.IO.File]::Exists($output)) {
     try {
+        [io.file]::OpenWrite($output).close()
+    } catch {
+        Write-Warning "Unable to write: $output"
+        if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
+            Write-Warning "Launching with 'Administrator' elevated privileges..."
+            Pause
+            Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
+            exit
+        } else {
+            Write-Output "FATAL: Unable to write with elevated privileges: $output"
+            Pause
+            exit 1
+        }
+    }
+
+    try {
         Write-Output ("Downloading: " + $output)
         Import-Module BitsTransfer
         $start_time = Get-Date