I'm trying to run a PowerShell script as administrator from python
As I cannot achieve this directly I tried running a batch file that run a PowerShell script
python run bat file
p = Popen([batFile, param1, param2, param3])
bat file run powershell
set param1=%1
set param2=%2
set param3=%3
PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dp0test.ps1"" ""%param1%"" ""%param2%"" ""%param3%""' -Verb RunAs}"
powershell code
param
(
[string]$param1,
[string]$param2,
[string]$param13
)
Write-Output $param1
Write-Output $param2
Write-Output $param3
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
My problem is that actually seems like the code is executed but the PowerShell is automatically closed after the write-output commands
Running the same files from windows cmd gives no issues, but when the code is executed from python the PowerShell terminal is automatically closed How can I avoid this?