antp wrote: 2025-08-02 07:45:28
Why do you need to create and execute a .ps1 rather than directly launching curl itself?
Good point, I think ps1 file is useless and curl could be included in vbs, never tested. I got this solution by steps (first version was a nightmare). I don't know visualbasic or powershell, it's vibe coding ... you know, Gemini, Perplexity ...
If you want to switch to curl, you have to use a trick. The problem is that curl open the output file and then fill it with html so when you use FileExists inside your script you don't know really if file is already ready or not. That is why in my script I create it as .tmp and only after curl command is completer I rename it with the filename used in FileExists.
With Launch() this is how to do this:
Launch(curlPath, ' --silent -L -w "%output{' + InstallerPath + curlOutputTmp + '}" --output "' + InstallerPath + curlOutput + '" --url "' + address + '" ' + '-H "Accept: text/html, */*" [.......] -H "User-Agent: ' + curlUserAgent + '" 2>$null &');
With -w "%output{' + InstallerPath + curlOutputTmp + '}" the file curlOutputTmp is created only when curl command is completed. Then you can get the html that is in curlOutput
Code: Select all
if (fileExists(InstallerPath + curlOutputTmp)) then
DeleteFile(InstallerPath + curlOutputTmp);
// please double check \" and fix, this is only a (working) test
Launch(curlPath, ' --silent -L -w "%output{' + InstallerPath + curlOutputTmp + '}" --output "' + InstallerPath + curlOutput + '" --url "' + address + '" ' + '-H "Accept: text/html, */*" -H "Accept-Language: it" -H "DNT: 1" -H "Priority: u=0, i" -H "Sec-Ch-Ua: \"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"" -H "Sec-Ch-Ua-Mobile: ?0" -H "Sec-Ch-Ua-Platform: \"Windows\"" -H "Sec-Fetch-Dest: Document" -H "Sec-Fetch-Mode: Navigate" -H "Sec-Fetch-Site: None" -H "Sec-Fetch-User: ?1" -H "Upgrade-Insecure-Requests: 1" -H "User-Agent: ' + curlUserAgent + '" 2>$null &');
cnt := 0;
// wait max 1 minute
while ((not fileExists(InstallerPath + curlOutputTmp)) AND (cnt < 120)) Do
begin
cnt := cnt + 1;
Sleep(500);
end;
if (fileExists(InstallerPath + curlOutputTmp)) then
begin
DeleteFile(InstallerPath + curlOutputTmp);
if (fileExists(InstallerPath + curlOutput)) then
begin
fileContent := TStringList.Create;
fileContent.LoadFromFile(InstallerPath + curlOutput);
Result := fileContent.Text;
fileContent.Free;
DeleteFile(InstallerPath + curlOutput);
end;
end;