windows: 从注册表读取系统版本号

windows 10 22h2 版本号是 19045
但 exe 版本号是 19041
This commit is contained in:
bin456789
2025-10-31 07:50:41 +08:00
parent 24a4446a02
commit 57a88a6bd9

View File

@ -758,17 +758,19 @@ is_windows_support_rdnss() {
[ "$build_ver" -ge 15063 ] [ "$build_ver" -ge 15063 ]
} }
get_windows_version_from_dll() { get_windows_version_from_windows_drive() {
local dll=$1 local os_dir=$1
[ -f "$dll" ] || error_and_exit "File not found: $dll"
apk add pev apk add hivex pev
local ver ntoskrnl_exe=$(find_file_ignore_case $os_dir/Windows/System32/ntoskrnl.exe)
ver="$(peres -v "$dll" | grep 'Product Version:' | awk '{print $NF}')" hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SOFTWARE)
echo "Version: $ver" >&2 IFS=. read -r nt_ver_major nt_ver_minor _ rev_ver _ \
IFS=. read -r nt_ver_major nt_ver_minor build_ver rev_ver _ < <(echo "$ver") < <(peres -v "$ntoskrnl_exe" | grep 'Product Version:' | awk '{print $NF}')
nt_ver="$nt_ver_major.$nt_ver_minor" nt_ver="$nt_ver_major.$nt_ver_minor"
apk del pev # win10 22h2 19045 的 exe/dll 版本还是 19041 的,因此要从注册表获取
build_ver=$(hivexget $hive 'Microsoft\Windows NT\CurrentVersion' CurrentBuildNumber)
echo "Version: $nt_ver_major.$nt_ver_minor.$build_ver.$rev_ver" >&2
apk del hivex pev
} }
is_elts() { is_elts() {
@ -3783,7 +3785,7 @@ modify_os_on_disk() {
# shellcheck disable=SC1090 # shellcheck disable=SC1090
# find_file_ignore_case 也在这个文件里面 # find_file_ignore_case 也在这个文件里面
. <(wget -O- $confhome/windows-driver-utils.sh) . <(wget -O- $confhome/windows-driver-utils.sh)
if ntoskrnl_exe=$(find_file_ignore_case /os/Windows/System32/ntoskrnl.exe 2>/dev/null); then if find_file_ignore_case /os/Windows/System32/ntoskrnl.exe >/dev/null 2>&1; then
# 其他地方会用到 # 其他地方会用到
is_windows() { true; } is_windows() { true; }
# 重新挂载为读写、忽略大小写 # 重新挂载为读写、忽略大小写
@ -3804,7 +3806,7 @@ modify_os_on_disk() {
mount -t ntfs3 -o nocase,rw,force /dev/$part /os mount -t ntfs3 -o nocase,rw,force /dev/$part /os
fi fi
# 获取版本号,其他地方会用到 # 获取版本号,其他地方会用到
get_windows_version_from_dll "$ntoskrnl_exe" get_windows_version_from_windows_drive /os
modify_windows /os modify_windows /os
return return
fi fi
@ -5723,8 +5725,7 @@ install_windows() {
# 3. 是否支持 sha256 # 3. 是否支持 sha256
# 4. Installation Type # 4. Installation Type
wimmount "$iso_install_wim" "$image_index" /wim/ wimmount "$iso_install_wim" "$image_index" /wim/
ntoskrnl_exe=$(find_file_ignore_case /wim/Windows/System32/ntoskrnl.exe) get_windows_version_from_windows_drive /wim
get_windows_version_from_dll "$ntoskrnl_exe"
windows_type=$(get_windows_type_from_windows_drive /wim) windows_type=$(get_windows_type_from_windows_drive /wim)
{ {
find_file_ignore_case /wim/Windows/System32/sacsess.exe && has_sac=true || has_sac=false find_file_ignore_case /wim/Windows/System32/sacsess.exe && has_sac=true || has_sac=false