如何通过命令行从 Microsoft 下载 Windows 10 ISO 文件?

如何通过命令行从 Microsoft 下载 Windows 10 ISO 文件?

我知道我可以使用 Microsoft 在其网站上提供的媒体创建工具下载官方 Windows 10 Pro ISO 映像:https://www.microsoft.com/en-us/software-download/windows10

但是,这个程序(“MediaCreationTool1809.exe”)似乎没有任何命令行选项。因此,我必须手动点击向导才能下载 ISO。

有没有办法自动地通过某种命令行过程下载 Windows 10 ISO?我想运行一个脚本来检查 Windows 10 Pro 的最新版本,然后,如果有新版本,则自动下载它。

答案1

据我所知,这是不可能的。

微软仅在每次发布主要版本时打包 Windows 10 ISO。通常每几个月打包一次。例如,2018 年 10 月和 2018 年 4 月的更新。

此外,您无需使用媒体创建工具。仅当您的浏览器使用 Windows 浏览器代理(即浏览器标识符)时,才会显示媒体创建工具。如果您将浏览器代理欺骗为另一个操作系统(即 macOS)之一,或者如果您从另一个平台的计算机访问 MS 网站的 Windows 10 部分,则完全有可能到达此屏幕。在此处输入图片描述

从这里,您可以选择版本和语言并下载。听起来很简单,对吧?只需进行简单查询,查看下拉对话框中是否有任何新内容,如果没有,则使用简单的拉取命令获取最新版本,对吧?

嗯,确实如此。但是,Microsoft 会为每种 ISO 组合生成个性化下载链接。这意味着生成的这些链接在创建后 24 小时就会过期,除非有人(除了我)设法从 Microsoft 以外的来源找到不会过期的 ISO 链接,否则几乎不可能实现。

TL;DR - 由于 Microsoft 的下载链接会在 24 小时后过期,因此使用命令行脚本自动拉下 Windows 10 ISO 很可能无法正常工作。

答案2

作为部分答案,您可以使用 Python 脚本至少检查是否已经下载了最新版本的 Windows 10:

# Microsoft only releases a new Windows 10 ISO when they do a big update every 6 months or so.
# This script will check the Microsoft web page to see if there is a new version.
# We cannot automatically download it because Microsoft provides custom-made links that expire after
# 24-hours.

# Configuration
ISO_DOWNLOAD_URL = 'https://www.microsoft.com/en-us/software-download/windows10ISO'

# Imports
import os
import requests
import sys
import webbrowser
from bs4 import BeautifulSoup

r = requests.get(ISO_DOWNLOAD_URL)
html = r.text.encode("utf-8")
soup = BeautifulSoup(html, 'html.parser')

# Compile a list of the current Windows 10 Editions
# We use BeautifulSoup to parse the HTML
# https://www.crummy.com/software/BeautifulSoup/
# We are looking for the following code:
'''
<select id="product-edition" href="#product-info-content">
    <option value="" selected="selected">Select edition</option>
    <optgroup label="Windows 10 October 2018 Update">
        <option value="1060">Windows 10</option>
    </optgroup>
    <optgroup label="Windows 10 April 2018 Update">
        <option value="651">Windows 10</option>
    </optgroup>
</select>
'''
most_recent_windows_edition = ''
for select in soup.find_all('select'):
    if select['id'] != 'product-edition':
        continue

    for optgroup in select.find_all('optgroup'):
        most_recent_windows_edition = optgroup['label']
        break

if most_recent_windows_edition == '':
    print('Failed to find the most recent Windows 10 edition in the retrieved HTML.')
    sys.exit(1)
print('The most recent version is: ' + most_recent_windows_edition)

# Get the directory of the script
# https://stackoverflow.com/questions/4934806/how-can-i-find-scripts-directory-with-python
DIR = os.path.dirname(os.path.realpath(__file__))

# Look to see if there is a directory for this edition already
if os.path.isdir(os.path.join(DIR, most_recent_windows_edition)):
    print('This version has already been downloaded.')

print('Still need to get this version. Use a user-agent switcher and switch to Linux to get the right ISO.')
webbrowser.open_new(ISO_DOWNLOAD_URL)

为了实现自动下载,可以使用像 Selenium 这样的无头浏览器来扩展此脚本,以模拟点击提示。我没有时间做所有这些,但这是可能的。

相关内容