1

I'm trying to run a Powershell command to download and run a exe. To be compatible with win 8.1 i'vs researched that i have to use ssl 1.2 (Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel) Although running this command:

[Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12

brings the error: The term ::SecurityProtocol is not recognized as the name of cmdlet, function, script file, or operable program. Checkthe spelling of the name, or if a path was included, verify that the path is correct and try again.

The whole command i'm running look like this:

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

Anybody know why this error occurs? Or is there even an easier way to run this? I've done much research and couldn't find anything helpful.

EDIT 1: After running the command in powershell directly (without the powershell.exe at the beginning) it worked fine (also replaced "&amp"; with "&") although running it through the msi installer it doesn't. My Custom Action in 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" ;
                                                                                                          &amp; $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install' Return='check'/>

EDIT 2

It seems to be that by building the Project it misses the statements in the square brackets atleast that causes the particular error message. Does Anybody know another way to write that statement or do i have to put something before/after the brackets?

2
  • &amp; is the only way to encode a literal & in an XML document, so it's indeed supposed to look like that in the wxs file. To execute a command straight from the command line you'll want to do powershell -command '<command text goes here>' Commented Jun 1, 2022 at 13:42
  • i tried it and saw in the log file that the command changed and that brought me an error: First it was: powershell --command "[Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 After running it the log showed this: powershell --command "::SecurityProtocol = ::Tls12 Commented Jun 1, 2022 at 14:09

1 Answer 1

0

I found the solution, you have to put the execommand in its own property, then you have to execute the property. This way the [] are not getting deleted:

 <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" ; &amp; $env:TEMP\MicrosoftEdgeWebview2Setup.exe /install'/>
 <CustomAction Id='DownloadAndInvokeBootstrapper' Directory="TARGETDIR" Execute="deferred" ExeCommand='[EXECOMMAND]' Return='check'/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.