我正在嘗試運行 Powershell 命令來下載和運行 exe。為了與 win 8.1 兼容,我研究過我必須使用 ssl 1.2(Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel)雖然運行此命令:
[Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
帶來錯誤:該術語::SecurityProtocol不被識別為 cmdlet、函式、腳本檔案或可運行程式的名稱。檢查名稱的拼寫,或者如果包含路徑,請驗證路徑是否正確并重試。
我正在運行的整個命令如下所示:
powershell.exe [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ;
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ;
& $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install
有誰知道為什么會發生這個錯誤?還是有更簡單的方法來運行它?我做了很多研究,找不到任何有用的東西。
編輯1:直接在powershell中運行命令后(開頭沒有powershell.exe)它作業正常(也用“&”替換了“&”),盡管通過msi安裝程式運行它卻沒有。我在 Product.wxs 中的自定義操作:
<CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='powershell.exe [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ;
& $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install' Return='check'/>
編輯 2
似乎是通過構建專案,它至少錯過了方括號中導致特定錯誤訊息的陳述句。有誰知道另一種寫該陳述句的方法,還是我必須在括號之前/之后放一些東西?
uj5u.com熱心網友回復:
我找到了解決方案,你必須把它放在execommand它自己的屬性中,然后你必須執行這個屬性。這樣[]就不會被洗掉:
<Property Id='EXECOMMAND' Value='powershell.exe -windowstyle hidden [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ; Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile "$env:TEMP\MicrosoftEdgeWebview2Setup.exe" ; & $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install'/>
<CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='[EXECOMMAND]' Return='check'/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/485655.html
