diff --git a/change/react-native-windows-2020-04-13-21-42-56-elevateForCert.json b/change/react-native-windows-2020-04-13-21-42-56-elevateForCert.json new file mode 100644 index 00000000000..f4d95f3f6d1 --- /dev/null +++ b/change/react-native-windows-2020-04-13-21-42-56-elevateForCert.json @@ -0,0 +1,8 @@ +{ + "type": "prerelease", + "comment": "Elevate to install app certificate if necessary", + "packageName": "react-native-windows", + "email": "asklar@microsoft.com", + "dependentChangeType": "patch", + "date": "2020-04-14T04:42:56.761Z" +} \ No newline at end of file diff --git a/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 b/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 index eb0c3c072c4..8aa87fdbaa0 100644 --- a/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 +++ b/vnext/local-cli/runWindows/utils/WindowsStoreAppUtils.ps1 @@ -132,14 +132,26 @@ function Install-App { [string] $Path, <# Full path to Add-AppDevPackage.ps1 #> [switch] $Force = $false ) - if (!$Force -and ((CheckIfNeedDeveloperLicense) -or (CheckIfNeedInstallCertificate (Join-Path $Path "..")))) + $needInstallCertificate = CheckIfNeedInstallCertificate (Join-Path $Path ".."); + $runningElevated = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"); + + if (!$Force -and ((CheckIfNeedDeveloperLicense) -or ($needInstallCertificate))) { # we can't run the script with -force param if license/certificate installation step is required Invoke-Expression ("& `"$Path`"") } else { - Invoke-Expression ("& `"$Path`" -force") + if (!$runningElevated) + { + $Path = [System.IO.Path]::GetFullPath($Path); + $process = Start-Process Powershell -ArgumentList "$Path -force" -Verb RunAs -ErrorAction Stop -PassThru + $process.WaitForExit(); + } + else + { + Invoke-Expression ("& `"$Path`" -force") -ErrorAction Stop + } } }