A couple of weeks ago I made a batch script, using curl, for downloading all Chrome executable files that I could find, for just in case Chrome gets messed up by an update.
Right after running the script, I didn't check to see if the executables are running fine, because I was assuming there wouldn't be a problem with them. So, after letting the script pile up Chrome versions, just a few days ago I got a big surprise when I tried installing an older version of Chrome. None of the files downloaded by the script worked. Each time I'd try running them, I'd get "unknown installer error".
This is the script:
#echo off
set date_and_time=#1_%date:~-10,2%-%date:~3,2%-%date:~-4,4%_%time:~0,2%.%time:~3,2%.%time:~6,2%.#2
md "%USERPROFILE%\Chrome_old_versions\"
set dirct="%USERPROFILE%\Chrome_old_versions\Chrome_%date:~-10,2%-%date:~3,2%-%date:~-4,4%_%time:~0,2%.%time:~3,2%.%time:~6,2%"
md "%dirct%"
cd "%dirct%"
curl --output-dir %dirct% https://dl.google.com/chrome/install/{ChromeStandaloneSetup64}.{exe} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/install/beta/{ChromeBetaStandaloneSetup64}.{exe} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/install/dev/{ChromeDevStandaloneSetup64}.{exe} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/install/{ChromeStandaloneSetup}.{exe} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/install/beta/{ChromeBetaStandaloneSetup}.{exe} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/install/dev/{ChromeDevStandaloneSetup}.{exe} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/mac/beta/{googlechromebeta}.{dmg} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/release2/q/canary/{googlechrome}.{dmg} -o %date_and_time%
curl --output-dir %dirct% https://dl.google.com/chrome/mac/dev/{googlechromedev}.{dmg} -o %date_and_time%
That got me curios about why isn't it working, so I accessed https://dl.google.com/chrome/install/ChromeStandaloneSetup64.exe in Chrome and that got me a perfectly working exe. The strange thing is both exes downloaded through Chrome and curl had the same sha 512 hash.
As I was puzzled, I tried wget and a powershell script.
For wget, I tried:
wget https://dl.google.com/chrome/install/ChromeStandaloneSetup64.exe --no-check-certificate
, which got me again "unknown installer error".
Thanks to #John Seerden, I then used his powershell script, which downloaded a googlechromestandaloneenterprise64.msi working executable.
Seeing this, I replaced googlechromestandaloneenterprise64.msi URL in his script with https://dl.google.com/chrome/install/ChromeStandaloneSetup64.exe, but still got that error.
$uri = "https://dl.google.com/chrome/install/googlechromestandaloneenterprise64.msi"
if (-not $PSScriptRoot) {
$PSScriptRoot = Split-Path -Parent -Path $script:MyInvocation.MyCommand.Definition
}
$outFile = "$PSScriptRoot\googlechromestandaloneenterprise64.msi"
Start-BitsTransfer -Source $uri -Destination $outFile
Start-Process -FilePath $outFile -Args "/qn" -Wait
I even tried downloading https://dl.google.com/chrome/install/googlechromestandaloneenterprise64.msi using wget and curl, but still got the error.
After some googling, I got across this post, which states something about getting an untagged installer, which I think has been downloaded through a 3rd party program like curl or wget, which ended in prompting "unknown installer error".
After some more googling, I got to this post, but instead of using Charles, I used Chrome Dev Tools to get the curl request from the Network tab. This didn't work either, same error.
Is it there any way I could download perfectly fine running Chrome executables through a script or is it there any way to fix the broken executables?
I would prefer to not resort to something like headless Chrome.
I used WinMerge for comparing these two standalone Chrome exes, version 86.0.4240.111 - 64 bits and 87.0.4280.66 - 64 bits, respectively ChromeStandaloneSetup64_28-10-2020_14.24.03_valid_Copy_old_version.exe (downloaded from https://dl.google.com/chrome/install/ChromeStandaloneSetup64.exe - broken exe aka missing the download URL tags within the exe) and ChromeStandaloneSetup64_valid_Copy_latest_version.exe (downloaded from https://www.google.com/chrome/?standalone=1&platform=win64 - valid exe aka exe that has the download URL tags within it).
As as a comparison, here's a tagged download URL:
https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B04A7785F-B8A2-B4AA-7A45-17861EB0DE70%7D%26lang%3Dro%26browser%3D4%26usagestats%3D1%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-stable-statsdef_1%26installdataindex%3Ddefaultbrowser/chrome/install/ChromeStandaloneSetup64.exe
and here is an untagged download URL:
https://dl.google.com/chrome/install/ChromeStandaloneSetup64.exe
While in WinMerge, I've searched for "&lang=ro&browser" in ChromeStandaloneSetup64_valid_Copy_latest_version.exe (the file to the right), then I went to Edit > Select Line Difference (F4), then to Merge > Copy to Left. Next, I went to File > Save As > Save Left As...
I then ran the resulting exe (patched exe, having version 86.0.4240.111 64 bits) in a fresh Windows 7 virtual machine (VM), and this time it installed correctly. For testing purposes, I turned off the network, and, when going to the 3 dotted menu in Chrome > Help > About Chrome, indeed, Chrome was the old version. After that, I turned on network and it had been updating to the latest version, 87.0.4280.66 64 bits, running with no problems.
Even though ChromeStandaloneSetup64_valid_Copy_latest_version.exe (valid exe) came with a Zone Identifier Alternate Data Stream (ADS), unlike the broken exe, the resulting exe coming out the broken exe, lacking ADS, it ran perfectly fine in the VM. Regarding ADS, I downloaded the same valid Chrome exe twice (87.0.4280.66 64 bits) and I noticed the ADS had the same exact value.
I also did additional tests and I've noticed if the resulting exe is lacking the appguid and iid fields, it won't install.
Another thing I did, it was messing around with the values in the respective fields, so I made the appguid and iid fields look like this:
appguid={00000000-0000-0000-0000-000000000000}&iid={00000000-0000-0000-0000-000000000000}
, which turned out to make the executable not install, getting Error code: 0x80070057.
Once I was done messing around with the exes editing, I started messing with the URL.
As for this given URL, coming from https://www.google.com/chrome/?standalone=1&platform=win64
(valid exe):
https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B04A7785F-B8A2-B4AA-7A45-17861EB0DE70%7D%26lang%3Dro%26browser%3D4%26usagestats%3D1%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-stable-statsdef_1%26installdataindex%3Ddefaultbrowser/chrome/install/ChromeStandaloneSetup64.exe
I trimmed down the appguid and iid, getting:
https://dl.google.com/tag/s/lang%3Dro%26browser%3D4%26usagestats%3D1%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-stable-statsdef_1%26installdataindex%3Ddefaultbrowser/chrome/install/ChromeStandaloneSetup64.exe
, which led to a broken exe, getting the same error code as above, Error code: 0x80070057.
Next thing I did was going to https://codebeautify.org/generate-random-data-from-regexp and generating a random appguid and iid (using hexadecimal values, because that's what I noticed it was being used in those fields) using this pattern:
[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}
, then using two different numbers:
038C42B4-AF87-AD38-990A-4384A7E29E04 - for appguid
EC7C4A9D-76CB-FBA7-D1C2-70EB689DA8F4 - for iid
, I got this link:
https://dl.google.com/tag/s/appguid%3D%7B038C42B4-AF87-AD38-990A-4384A7E29E04%7D%26iid%3D%7BEC7C4A9D-76CB-FBA7-D1C2-70EB689DA8F4%7D%26lang%3Dro%26browser%3D4%26usagestats%3D1%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-stable-statsdef_1%26installdataindex%3Ddefaultbrowser/chrome/install/ChromeStandaloneSetup64.exe
, which, during installation, got me "Unable to connect to the Internet. If you use a firewall, please whitelist GoogleUpdate.exe" error.
So, since the appguid and iid were coming from a later version of Chrome (appguid and iid taken from 87.0.4280.66 and inserted into 86.0.4240.111), I assume, installation will finish successfully only if the appguid and iid contained in the exe itself, through computation during instalation, will yield a result that matches a value stored somewhere in the exe, or a value that also gets computed during installation. I say this, because when I installed the resulting valid standalone Chrome exe coming from the broken exe, the network was turned off, and there was no prior installation of Chrome on that system. Or maybe those two values are somehow tied to the operating system.
I conclusion, I think I'll end up modifing the URLs in the batch file with those appguid and iid, unless I decide to take a closer look at the URLs of the upcoming releases of Chrome to get an even better idea of how all of this is working.
These:
8A69D345-D564-463C-AFF1-A69D9E530F96 - for appguid
04A7785F-B8A2-B4AA-7A45-17861EB0DE70 - for iid
$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $Path\$Installer; Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path\$Installer
Once the process is completed, you will see ‘Google Chrome’ icon on your Desktop. Click and run it
I have been able to use curl to issue a query and return a result or series of named parameters.
I want to issue a POST command on these series of named parameters, but the "multiple" is tripping me up.
I can issue the POST command on one of the parameters, but not on the entire series of them.
The command I'm using within powershell is
curl.exe -u username:password -X POST http://site.url:8042/modalities/MCTEST/store -d '["6a3eb7c4-a9d83950-24d36e94-5c20d248-0b5ce989","8c93b430-757278ab-21ab643c-c98aa03d-da14148e","b8f648fa-175de243-de76b1c0-2dc7551a-928b86a5","c865b966-f0c7d2c2-0a1114e0-80531305-31cd104e","aac7f73f-fcb922ef-b950c4c1-ee1d512e-e2aeb5ae"]'
If I issue the command on only one, it processes fine...obviously, I don't need quotes or brackets, which I think is what is tripping me up.
curl.exe -u username:password -X POST http://site.url:8042/modalities/MCTEST/store -d 6a3eb7c4-a9d83950-24d36e94-5c20d248-0b5ce989
I've tried subbing the double quotes with a backslash, tried adding a backslash, I've tried everything i can think of...I'm missing something.
I get a response of "must provide a json value"
I'm not sure what my error is in my syntax.
Any ideas?
external commands have to be called/quoted properly
PowerShell: Running Executables
Solve Problems with External Command Lines in PowerShell
Top 5 tips for running external commands in Powershell
Execution of External Commands in PowerShell Done Right
Using Windows PowerShell to run old command-line tools (and their
weirdest parameters)
See also about Redirection
Powershell: Pipe external command output to another external command
How to use the curl command in PowerShell?
Stackoverflow example by Ansgar Wiechers
$CurlArgument = '-u', 'xxx#gmail.com:yyyy',
'-X', 'POST',
'https://xxx.bitbucket.org/1.0/repositories/abcd/efg/pull-requests/2229/comments',
'--data', 'content=success'
$CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe'
& $CURLEXE #CurlArgument
I'm using GitLab.com with a Windows OS runner, so we commonly use PowerShell in place of Bash for scripting steps in the console. I'm trying to use pnpm and the examples they give suggest the following
$ curl -L https://unpkg.com/#pnpm/self-installer | node
$ install pnpm
What's the PowerShell version of the above curl requests piped into node?
I've been trying both Invoke-RestMethod and using the curl alias from within PowerShell, like
PS> curl https://unpkg.com/#pnpm/self-installer | node
but have been getting
SyntaxError: Invalid or unexpected token
Also from the curl docs, I know --location is needed.
As a best practice within scripts, I'd suggest explicitly using the parameter names and passing the correct type rather than letting the interpreter coerce for you (Uri takes a System.Uri and System is imported to PowerShell as a default):
$uri = [Uri]'https://unpkg.com/#pnpm/self-installer'
$js = Invoke-RestMethod -Uri $uri
The reason for your syntax error? the # symbol is special in PowerShell for a feature called Splatting.
When I ran the above, it spit out the contents of a js script to my console. It can then be assumed node takes cli, piped input and is in your PATH:
$js | node
Another assumption is you have an install in your PATH or the script creates some kind of interactive terminal:
$ install pnpm
--location isn't necessary here since Invoke-RestMethod will follow a redirect up to 5 hops by default (this can be configured with MaximumRedirection).
I am trying to connect (in PowerShell) via
curl
but with no success.
Below is the following code I've inserting in order to establish the connection:
curl -u <USER>:<PASSWORD> https://something.com
but got the error:
Invoke-WebRequest : Parameter cannot be processed because the parameter name 'u' is ambiguous.
Possible matches include: -UseBasicParsing -Uri -UseDefaultCredentials -UserAgent.
So, I tried to look for a solution at SO, such as:
PowerShell's Invoke-RestMethod equivalent of curl -u (Basic Authentication)
Running cURL on 64 bit Windows
and on GitHub:
https://github.com/PowerShell/PowerShell/issues/4351
But got no success.
I also reinstalled the 'curl' in my machine and tried to use Invoke-WebRequest directly, but the problem persisted.
I'm new at PowerShell, maybe I'm doing a mistake when coding those lines, but do you have any suggestion how to deal with?
Do you think there is a better Command Prompt/CLI than PowerShell to use curl?
As #Maximilian Burszley wrote, curl in PowerShell is an alias to another command, not the curl command you intended.
In my opinion the simplest solution is to remove the alias, and then the curl command will be available without the overhead of Get-Alias and without using curl with the executable's path.
This is the command to remove the curl alias when using Windows PowerShell:
Remove-item alias:curl
I am attempting to use the TeamForge API. This is my first dip into web requests so I am sure I am missing something obvious.
To even begin, I realize I need to request an oauth token. According to the documentation, I have to execute the following command:
# Base URL of TeamForge site.
site_url="https://teamforge.example.com"
# TeamForge authentication credentials.
username="foo"
password="bar"
# Requested scope (all)
scope="urn:ctf:services:ctf urn:ctf:services:svn urn:ctf:services:gerrit urn:ctf:services:soap60"
curl -d "grant_type=password&client_id=api-client&scope=$scope&username=$username&password=$password" $site_url/oauth/auth/token
Seems fairly straightforward. Knowing that curl is an alias for Invoke-WebRequest, I attempted to run the following in PowerShell:
$site="https://my.teamforge.site"
$user="myuser"
$pass="mypass"
$scope="urn:ctf:services:ctf"
curl "grant_type=password&client_id=api-client&scope=$scope&username=$user&password=$pass" -Uri $site/oauth/auth/token
What I got was an error:
Invoke-WebRequest : A positional parameter cannot be found that accepts argument
'grant_type=password&client_id=api-client&scope=urn:ctf:services:ctf&username= rest of line redacted for obvious reasons
I took this to mean I fudged the syntax. I have no clue where to start taking this appart and plugging it into Invoke-WebRequest command. Like I said, this is my first time attempting this. My searches for answers thus far has not been helpful. I think I am asking the wrong questions.
How do I deconstruct this curl command so that I can convert it to something I can use in PowerShell?