Execute HTTP/S stream on Windows

0

How to execute HTTPS download link to an exe file directly?

Sergei

Posted 2016-04-26T06:16:33.997

Reputation: 159

Answers

0

You can't directly run a file from the web, but you can download the file first, then run it. This PowerShell one-liner ought to do it:

[System.IO.File]::WriteAllBytes("tmpfile.exe", (Invoke-WebRequest "https://example.com/app.exe").Content); Start-Process tmpfile.exe

That will leave behind a tmpfile.exe program in the current directory. To instead leave it in the Temp directory (where it will hopefully be cleaned up soon):

$tmpPath = [System.IO.Path]::GetTempFileName() + ".exe"; [System.IO.File]::WriteAllBytes($tmpPath, (Invoke-WebRequest "https://example.com/app.exe").Content); Start-Process $tmpPath

Using these, you could probably rig up a script to download and run an EXE from an arbitrary URL. You can invoke a PowerShell command from a normal command prompt or batch file by putting powershell -command before it:

@echo off
rem Downloads and runs an EXE from a URL.
powershell -command $tmpPath = [System.IO.Path]::GetTempFileName() + '.exe'; [System.IO.File]::WriteAllBytes($tmpPath, (Invoke-WebRequest "%*").Content); Start-Process $tmpPath

Ben N

Posted 2016-04-26T06:16:33.997

Reputation: 32 973