Windows 批处理文件请求管理员权限并在curl 中下载文件失败

发布于 2025-01-11 05:31:45 字数 1161 浏览 1 评论 0原文

我有一个像这样的批处理文件,

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2025-01-18 05:31:45

Github 上文件的链接不是直接链接,因此如果您尝试简单地curl 文件,最终只会下载重定向页面。如果您使用文本编辑器打开已下载的文件,您会看到

<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>

这应该告诉您需要使用 -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 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文