使用繁體中文,在w11下使用pytho語言,使用UI界面,預設UI400*400,畫面如圖片方式,要如何取得ISO檔案的內的版本清單,並顯示在UI界面上,如圖片的方式?
使用繁體中文,在w11下使用pytho語言,使用UI界面,預設UI400*400,畫面如圖片方式,要如何取得ISO檔案的內的版本清單,並顯示在UI界面上,如圖片的方式? 使用檔案總管掛載iso檔後,用指令"dism /Get-WimInfo /WimFile:X:\sources\install.wim /index:1 "
pip install pycdlib
pip install iso9660
dism /Get-WimInfo /WimFile:X:\sources\install.wim /index:1
鍵入與安裝檔案類型對應的以下命令。將 [X] 替換為掛載 ISO 檔案的相應驅動器號,然後按下 Enter 鍵。
如果 install.wim,然後鍵入 dism /Get-WimInfo /WimFile:[X]:\sources\install.wim /index:1
如果 install.swm,然後鍵入 dism /Get-WimInfo /WimFile:[X]:\sources\install.swm /index:1
如果 install.esd,然後鍵入 dism /Get-WimInfo /WimFile:[X]:\sources\install.esd /index:1
1131107-win-version-0
-字改成12
import tkinter as tk
from tkinter import filedialog
import subprocess
import re
import threading
def get_iso_info(iso_path):
# 挂载ISO文件
mount_command = f'PowerShell "Mount-DiskImage -ImagePath \'{iso_path}\'"'
subprocess.run(mount_command, shell=True, check=True)
# 获取挂载点
get_drive_command = f'PowerShell "(Get-DiskImage -ImagePath \'{iso_path}\' | Get-Volume).DriveLetter"'
drive_letter = subprocess.check_output(get_drive_command, shell=True).decode().strip() + ':'
# 获取WIM文件信息
versions = []
for index in range(1, 6): # index:1最多到index:5
wim_command = f'dism /Get-WimInfo /WimFile:{drive_letter}\\sources\\install.wim /index:{index}'
try:
output = subprocess.check_output(wim_command, shell=True).decode('big5', errors='ignore')
name = re.search(r"名稱\s*:\s*(.+)", output).group(1)
version = re.search(r"版本\s*:\s*(.+)", output).group(1)
versions.append((index, name, version))
except subprocess.CalledProcessError:
break # 如果索引超出范围,则停止循环
# 卸载ISO文件
unmount_command = f'PowerShell "Dismount-DiskImage -ImagePath \'{iso_path}\'"'
subprocess.run(unmount_command, shell=True, check=True)
return versions
def update_listbox(versions):
# 更新UI的listbox
listbox.delete(0, tk.END)
for index, name, version in versions:
listbox.insert(tk.END, f"[{index}] {name} 版本:{version}")
def select_iso():
iso_path = filedialog.askopenfilename(filetypes=[("ISO files", "*.iso")])
if iso_path:
iso_entry.delete(0, tk.END)
iso_entry.insert(0, iso_path)
# 在新的執行緒中執行 get_iso_info
def worker():
versions = get_iso_info(iso_path)
# 更新UI,注意要使用 `app.after()` 把更新操作放回主線程
app.after(0, update_listbox, versions)
# 創建並啟動子執行緒
threading.Thread(target=worker, daemon=True).start()
app = tk.Tk()
app.title("取得Windows版本清單")
app.geometry("600x300")
# 创建框架来组织布局
frame = tk.Frame(app)
frame.pack(pady=20)
# 設置 Label 和 Entry 控制項的字體為 14
font = ("Arial", 12)
# Label, Entry 和 Button 都使用相同的字體
tk.Label(frame, text="Windows ISO", font=font).pack(side=tk.LEFT)
iso_entry = tk.Entry(frame, width=50, font=font) # 設定 Entry 字體
iso_entry.pack(side=tk.LEFT)
tk.Button(frame, text="...", command=select_iso, font=font).pack(side=tk.LEFT) # 設定 Button 字體
# 設置 "版本清單" 的 Label 和 Listbox 的字體為 14
tk.Label(app, text="版本清單", font=font).pack()
listbox = tk.Listbox(app, width=50, font=font) # 設定 Listbox 字體
listbox.pack()
note_label = tk.Label(text="by 資訊組 FSPS-新北市中和區復興國小", font=("Arial", 10), fg="seagreen")
note_label.place(relx=0.99, rely=0.99, anchor='se')
app.mainloop()
1131107-win-version-02
-解決卡住狀態
import tkinter as tk
from tkinter import filedialog
import subprocess
import re
import threading
def get_iso_info(iso_path):
# 挂载ISO文件
mount_command = f'PowerShell "Mount-DiskImage -ImagePath \'{iso_path}\'"'
subprocess.run(mount_command, shell=True, check=True)
# 获取挂载点
get_drive_command = f'PowerShell "(Get-DiskImage -ImagePath \'{iso_path}\' | Get-Volume).DriveLetter"'
drive_letter = subprocess.check_output(get_drive_command, shell=True).decode().strip() + ':'
# 获取WIM文件信息
versions = []
for index in range(1, 6): # index:1最多到index:5
wim_command = f'dism /Get-WimInfo /WimFile:{drive_letter}\\sources\\install.wim /index:{index}'
try:
output = subprocess.check_output(wim_command, shell=True).decode('big5', errors='ignore')
name = re.search(r"名稱\s*:\s*(.+)", output).group(1)
version = re.search(r"版本\s*:\s*(.+)", output).group(1)
versions.append((index, name, version))
except subprocess.CalledProcessError:
break # 如果索引超出范围,则停止循环
# 卸载ISO文件
unmount_command = f'PowerShell "Dismount-DiskImage -ImagePath \'{iso_path}\'"'
subprocess.run(unmount_command, shell=True, check=True)
return versions
def update_listbox(versions):
# 更新UI的listbox
listbox.delete(0, tk.END)
for index, name, version in versions:
listbox.insert(tk.END, f"[{index}] {name} 版本:{version}")
def select_iso():
iso_path = filedialog.askopenfilename(filetypes=[("ISO files", "*.iso")])
if iso_path:
iso_entry.delete(0, tk.END)
iso_entry.insert(0, iso_path)
# 在新的執行緒中執行 get_iso_info
def worker():
versions = get_iso_info(iso_path)
# 更新UI,注意要使用 `app.after()` 把更新操作放回主線程
app.after(0, update_listbox, versions)
# 創建並啟動子執行緒
threading.Thread(target=worker, daemon=True).start()
app = tk.Tk()
app.title("取得Windows版本清單")
app.geometry("600x300")
# 创建框架来组织布局
frame = tk.Frame(app)
frame.pack(pady=20)
tk.Label(frame, text="Windows ISO").pack(side=tk.LEFT)
iso_entry = tk.Entry(frame, width=50)
iso_entry.pack(side=tk.LEFT)
tk.Button(frame, text="...", command=select_iso).pack(side=tk.LEFT)
tk.Label(app, text="版本清單").pack()
listbox = tk.Listbox(app, width=50)
listbox.pack()
note_label = tk.Label(text="by 資訊組 FSPS-新北市中和區復興國小", font=("Arial", 10), fg="seagreen")
note_label.place(relx=0.99, rely=0.99, anchor='se')
app.mainloop()
1131107-win-version-01
-以下執行時會卡住UI
import tkinter as tk
from tkinter import filedialog
import subprocess
import re
def get_iso_info(iso_path):
# 挂载ISO文件
mount_command = f'PowerShell "Mount-DiskImage -ImagePath \'{iso_path}\'"'
subprocess.run(mount_command, shell=True, check=True)
# 获取挂载点
get_drive_command = f'PowerShell "(Get-DiskImage -ImagePath \'{iso_path}\' | Get-Volume).DriveLetter"'
drive_letter = subprocess.check_output(get_drive_command, shell=True).decode().strip() + ':'
# 获取WIM文件信息
versions = []
for index in range(1, 6): # index:1最多到index:5
wim_command = f'dism /Get-WimInfo /WimFile:{drive_letter}\\sources\\install.wim /index:{index}'
try:
output = subprocess.check_output(wim_command, shell=True).decode('big5', errors='ignore')
name = re.search(r"名稱\s*:\s*(.+)", output).group(1)
version = re.search(r"版本\s*:\s*(.+)", output).group(1)
versions.append((index, name, version))
except subprocess.CalledProcessError:
break # 如果索引超出范围,则停止循环
# 卸载ISO文件
unmount_command = f'PowerShell "Dismount-DiskImage -ImagePath \'{iso_path}\'"'
subprocess.run(unmount_command, shell=True, check=True)
return versions
def select_iso():
iso_path = filedialog.askopenfilename(filetypes=[("ISO files", "*.iso")])
if iso_path:
iso_entry.delete(0, tk.END)
iso_entry.insert(0, iso_path)
versions = get_iso_info(iso_path)
listbox.delete(0, tk.END)
for index, name, version in versions:
listbox.insert(tk.END, f"[{index}] {name} 版本:{version}")
app = tk.Tk()
app.title("取得Windows版本清单")
app.geometry("600x300")
# 创建框架来组织布局
frame = tk.Frame(app)
frame.pack(pady=20)
tk.Label(frame, text="Windows ISO").pack(side=tk.LEFT)
iso_entry = tk.Entry(frame, width=50)
iso_entry.pack(side=tk.LEFT)
tk.Button(frame, text="...", command=select_iso).pack(side=tk.LEFT)
tk.Label(app, text="版本清单").pack()
listbox = tk.Listbox(app, width=50)
listbox.pack()
note_label = tk.Label(text="by 資訊組 FSPS-新北市中和區復興國小", font=("Arial", 10), fg="seagreen")
note_label.place(relx=0.99, rely=0.99, anchor='se')
app.mainloop()