Windows 批处理文件请求管理员权限并在curl 中下载文件失败
我有一个像这样的批处理文件,
@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
它要求管理员权限并执行curl来下载文件,但不幸的是,即使给出了管理员权限,下载的zip文件也只有1Kb,整个zip文件没有正确下载, 控制台窗口也不会显示错误。
任何人都可以帮忙出什么问题了吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Github 上文件的链接不是直接链接,因此如果您尝试简单地
curl
文件,最终只会下载重定向页面。如果您使用文本编辑器打开已下载的文件,您会看到这应该告诉您需要使用
-L
标志来跟踪重定向:curl -L“https://github.com/ruellm/OrthoSelect_6.7.5/archive/refs/tags/6.7.5.zip”-o 6.7.5.zip
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 seeThis 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