Home > Enterprise >  Windows batchfile asking for admin rights and download a file in curl fails
Windows batchfile asking for admin rights and download a file in curl fails

Time:03-03

I have a batch file like this

@echo off

::::::::::::::::::::::::::::::::::::::::::::
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' (goto gotPrivileges) else (goto getPrivileges)
:getPrivileges
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo For Each strArg in WScript.Arguments >> "%temp%\getadmin.vbs"
echo If strArg = WScript.Arguments.Item^(0^) Then d = Left^(strArg, InStrRev^(strArg,"\"^) - 1^) >> "%temp%\getadmin.vbs"
echo args = args ^& " " ^& strArg  >> "%temp%\getadmin.vbs"
echo Next >> "%temp%\getadmin.vbs"
echo UAC.ShellExecute "cmd.exe", ^("/c start /D """ ^& d ^& """ /B" ^& args ^& " ^& exit"^), , "runas", 4 >> "%temp%\getadmin.vbs"
cscript "%temp%\getadmin.vbs" ""%~s0"" %*
del /q "%temp%\getadmin.vbs"
exit /b
:gotPrivileges
:: Your code here

echo "Downloading old version of OrthoSelect..."

curl -o ./6.7.5.zip "https://github.com/ruellm/OrthoSelect_6.7.5/archive/refs/tags/6.7.5.zip"

pause

It ask for an admin permission and executes curl to download the file, but unfortunately, even if the admin rights is given, the zip file downloaded is only 1Kb, the entire zip file is not downloaded properly, The console window do not show error as well.

Anyone can help whats wrong?

CodePudding user response:

Links to files on Github are not direct links, so if you try to simply curl the file, you'll end up only downloading the redirect page instead. If you use a text editor to open the file that you've downloaded, you'll see

<html><body>You are being <a href="https://codeload.github.com/ruellm/OrthoSelect_6.7.5/zip/refs/tags/6.7.5">redirected</a>.</body></html>

This should tell you that you need to use the -L flag to follow redirects:
curl -L "https://github.com/ruellm/OrthoSelect_6.7.5/archive/refs/tags/6.7.5.zip" -o 6.7.5.zip

  • Related