Compare commits

...

5 Commits

Author SHA1 Message Date
7a02021d5d core: 不重要的优化 2026-04-26 06:16:47 +08:00
67fd6385a7 windows: 删除 ProtectYourPC 设置,使首次登录可自定义隐私选项 2026-04-26 06:16:47 +08:00
f6beb50722 windows: 优化安装流程 2026-04-26 06:16:47 +08:00
c8c1da2dbc core: 优化 powershell 查询
- 避免 wmic where 条件有空格时报错
- 减少 ForEach-Object 以提高速度
2026-04-26 06:16:46 +08:00
b1e995a2f0 windows: 国内服务器访问 intel.cn 2026-04-26 06:16:46 +08:00
8 changed files with 184 additions and 79 deletions

View File

@ -331,7 +331,7 @@ bash reinstall.sh netboot.xyz
- If remote login fails, try using the username `.\administrator`.
- The machine with a static IP will automatically configure the IP. It may take a few minutes to take effect on the first boot.
- Supports ISO images in any language.
- Supports bypassing Windows 11 hardware requirements.
- Automatically bypassing Windows 11 hardware requirements.
#### Supported Systems
@ -582,12 +582,14 @@ bash reinstall.sh reset
According to the Law of Bug Conservation, fixing old bugs often introduces new ones.
If a new bug occurs, try using an older version to see if it works.
If a bug occurs, try using an older version to see if it works.
Go to <https://github.com/bin456789/reinstall/commits/main> and find the old versions `commit_id` on the right side.
Replace `xxxxxxxx` in the script below with the `commit_id` of an older version and run the script.
```bash
commit_id=xxxxxxx
commit_id=xxxxxxxx
curl -O https://raw.githubusercontent.com/bin456789/reinstall/$commit_id/reinstall.sh || wget -O ${_##*/} $_
sed -i "/^confhome.*main$/s/main/$commit_id/" reinstall.sh
bash reinstall.sh ...
@ -598,6 +600,7 @@ bash reinstall.sh ...
1. Fork this repository.
2. Modify the `confhome` and `confhome_cn` at the beginning of `reinstall.sh` and `reinstall.bat`.
3. Make changes to the other code.
4. Download and run your `reinstall.sh` or `reinstall.bat`."
## Thanks

View File

@ -331,7 +331,7 @@ bash reinstall.sh netboot.xyz
- 如果远程登录失败,可以尝试使用用户名 `.\administrator`
- 静态机器会自动配置好 IP可能首次开机几分钟后才生效
- 支持任意语言的 ISO
- 支持绕过 Windows 11 硬件限制
- 自动绕过 Windows 11 硬件限制
#### 支持的系统
@ -582,12 +582,14 @@ bash reinstall.sh reset
根据 Bug 守恒定律,修复旧 Bug 的同时会引入新的 Bug
如果遇到新的 Bug,可以试下旧版本是否正常
如果脚本出现问题,可以试下旧版本是否正常
<https://github.com/bin456789/reinstall/commits/main> 右侧找到旧版本的 `commit_id`
将下面脚本的 `xxxxxxxx` 替换成旧版本的 `commit_id` 并运行脚本
```bash
commit_id=xxxxxxx
commit_id=xxxxxxxx
curl -O https://raw.githubusercontent.com/bin456789/reinstall/$commit_id/reinstall.sh || wget -O ${_##*/} $_
sed -i "/^confhome.*main$/s/main/$commit_id/" reinstall.sh
bash reinstall.sh ...
@ -598,6 +600,7 @@ bash reinstall.sh ...
1. Fork 本仓库
2. 修改 `reinstall.sh``reinstall.bat` 开头的 `confhome``confhome_cn`
3. 修改其它代码
4. 下载并运行你的 `reinstall.sh``reinstall.bat`
## 感谢

View File

@ -643,13 +643,12 @@ wmic() {
curl -Lo "$tmp/wmic.ps1" "$confhome/wmic.ps1"
fi
# shellcheck disable=SC2046
powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass \
-File "$(cygpath -w "$tmp/wmic.ps1")" \
-Namespace "$namespace" \
-Class "$class" \
$([ -n "$filter" ] && echo -Filter "$filter") \
$([ -n "$props" ] && echo -Properties "$props")
${filter:+"-Filter"} ${filter:+"$filter"} \
${props:+"-Properties"} ${props:+"$props"}
}
is_virt() {
@ -703,12 +702,6 @@ is_virt() {
$_is_virt
}
is_absolute_path() {
# 检查路径是否以/开头
# 注意语法和 ash 不同
[[ "$1" = /* ]]
}
is_cpu_supports_x86_64_v3() {
# 用 ld.so/cpuid/coreinfo.exe 更准确
# centos 7 /usr/lib64/ld-linux-x86-64.so.2 没有 --help
@ -3230,7 +3223,7 @@ build_cmdline() {
# 脚本可能多次运行,先清理之前的残留
mkdir_clear() {
dir=$1
local dir=$1
if [ -z "$dir" ] || [ "$dir" = / ]; then
return
@ -3893,6 +3886,7 @@ This script is outdated, please download reinstall.sh again.
if [ "$hold" = 0 ]; then
info 'hold 0'
echo "Edit $tmp if needed."
read -r -p 'Press Enter to continue...'
fi

View File

@ -5738,10 +5738,15 @@ get_filesize_mb() {
du -m "$1" | awk '{print $1}'
}
is_absolute_path() {
# 检查路径是否以/开头
# 注意语法和 bash 不同
[[ "$1" = "/*" ]]
mkdir_clear() {
local dir=$1
if [ -z "$dir" ] || [ "$dir" = / ]; then
return
fi
rm -rf "$dir"
mkdir -p "$dir"
}
# 注意使用方法是 list=$(list_add "$list" "$item_to_add")
@ -5812,6 +5817,22 @@ get_windows_arch_from_windows_drive() {
apk del hivex
}
get_intel_download_url() {
local id=$1
local file_regex=$2
if is_in_china; then
local url=https://www.intel.cn/content/www/cn/zh/download/$id.html
else
local url=https://www.intel.com/content/www/us/en/download/$id.html
fi
# 将双引号替换成换行符,使每个链接占一行
# intel 禁止了 wget 下载网页
wget -U curl/7.54.1 "$url" -O- | sed 's,",\n,g' |
grep -Eio -m1 "https://.+/$file_regex" | grep .
}
install_windows() {
get_wim_prop() {
wim=$1
@ -5998,7 +6019,7 @@ install_windows() {
# 检测 sac 和 nvme
{
find_file_ignore_case /wim/Windows/System32/sacsess.exe && has_sac=true || has_sac=false
find_file_ignore_case /wim/Windows/INF/stornvme.inf && has_stornvme=true || has_stornvme=false
find_file_ignore_case /wim/Windows/System32/drivers/stornvme.sys && has_stornvme=true || has_stornvme=false
} >/dev/null 2>&1
# 检测是否支持 sha256 签名的驱动
@ -6218,8 +6239,9 @@ install_windows() {
add_drivers() {
info "Add drivers"
# 驱动下载临时文件夹
drv=/os/drivers
mkdir -p "$drv" # 驱动下载临时文件夹
mkdir_clear "$drv"
# 这里有坑
# $(get_cloud_vendor) 调用了 cache_dmi_and_virt
@ -6377,9 +6399,7 @@ install_windows() {
2025) echo 838943 ;;
esac
)
# intel 禁止了 wget 下载网页
wget -U curl/7.54.1 https://www.intel.com/content/www/us/en/download/$id.html -O- |
grep -Eio -m1 "\"https://.+/(Wired_driver|prowin).*${arch_intel}(legacy)?\.(zip|exe)\"" | tr -d '"' | grep .
get_intel_download_url "$id" "(Wired_driver|prowin).*${arch_intel}(legacy)?\.(zip|exe)"
;;
esac ;;
esac
@ -6729,8 +6749,7 @@ EOF
cp_drivers $drv/virtio -ipath "*/$virtio_sys/$arch/*" "$@"
fi
else
# coreutils 的 cp mv rm 才有 -v 参数
apk add 7zip file coreutils
apk add 7zip file
download $baseurl/$dir/virtio-win-gt-$arch_xdd.msi $drv/virtio.msi
match="FILE_*_${virtio_sys}_${arch}*"
7z x $drv/virtio.msi -o$drv/virtio -i!$match -y -bb1
@ -7063,6 +7082,8 @@ EOF
}
add_driver_vmd() {
info "Add drivers: VMD"
# RST v20 不支持 11代 PCI\VEN_8086&DEV_9A0B
support_v19=false
support_v20=false
@ -7080,18 +7101,16 @@ EOF
fi
done
local page=
local id
if $support_v20 && [ "$build_ver" -ge 19041 ]; then
page=https://www.intel.com/content/www/us/en/download/849936.html
id=849936
elif $support_v19 && [ "$build_ver" -ge 15063 ]; then
page=https://www.intel.com/content/www/us/en/download/849933.html
id=849933
fi
if [ -n "$page" ]; then
# intel 禁止了 wget 下载网页
if [ -n "$id" ]; then
local url
url=$(wget -U curl/7.54.1 "$page" -O- |
grep -Eio -m1 "\"https://.+/SetupRST\.exe\"" | tr -d '"' | grep .)
url=$(get_intel_download_url "$id" "SetupRST\.exe")
# 注意 intel 禁止了 aria2 下载
download $url $drv/SetupRST.exe

View File

@ -1,6 +1,6 @@
#!/bin/ash
# shellcheck shell=dash
# shellcheck disable=SC3001,SC3003,SC3010
# shellcheck disable=SC3001,SC3003,SC3010,SC3015
# reinstall.sh / trans.sh 共用此文件
# grep 无法处理 UTF-16LE 编码的 inf有以下几种解决方法
@ -239,6 +239,27 @@ list_files_from_inf() {
done < <(echo "$inf_txts")
}
is_x_starts_with_y() {
[[ "$1" =~ ^"$2" ]]
}
is_x_ends_with_y() {
[[ "$1" =~ "$2"$ ]]
}
is_absolute_path() {
# 检查路径是否以/开头
# alpine ash 可用
# [[ "$1" = "/*" ]]
# bash 可用
# [[ "$1" = /* ]]
# 都可用
is_x_starts_with_y "$1" /
}
# windows 安装驱动时,只会安装相同架构的驱动文件到系统,即使 inf 里有列出其它架构的驱动
# 因此 DISM 导出驱动时,也就没有包含其它架构的驱动文件
@ -284,7 +305,11 @@ get_path_in_correct_case() {
output="$output$part/"
else
# 最后 part
output="$output$part"
if is_x_ends_with_y "$path" /; then
output="$output$part/"
else
output="$output$part"
fi
fi
shift
done

View File

@ -49,31 +49,24 @@ if exist X:\custom_drivers\ (
rem 等待加载分区
call :sleep 5000
echo rescan | diskpart
rem 判断 efi 还是 bios
rem 或者用 https://learn.microsoft.com/windows-hardware/manufacture/desktop/boot-to-uefi-mode-or-legacy-bios-mode
rem pe 下没有 mountvol
echo list vol | diskpart | find "efi" && (
set BootType=efi
) || (
set BootType=bios
)
call :sleep 5000
rem 获取 ProductType
rem for /f "tokens=3" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v ProductType') do (
rem set "ProductType=%%a"
rem )
rem 获取 BuildNumber
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
set "BuildNumber=%%a"
)
rem 获取 installer 卷 id
for /f "tokens=2" %%a in ('echo list vol ^| diskpart ^| find "installer"') do (
set "VolIndex=%%a"
)
rem 及时退出
if "%VolIndex%"=="" (
echo "Error: Cannot find installer partition." >&2
exit /b 1
)
rem 将 installer 分区设为 Y 盘
(echo select vol %VolIndex% & echo assign letter=Y) | diskpart
@ -93,6 +86,15 @@ for /f "tokens=3" %%a in (X:\disk.txt) do (
)
del X:\disk.txt
rem 判断 efi 还是 bios
rem 或者用 https://learn.microsoft.com/windows-hardware/manufacture/desktop/boot-to-uefi-mode-or-legacy-bios-mode
rem pe 下没有 mountvol
echo list vol | diskpart | find "efi" && (
set BootType=efi
) || (
set BootType=bios
)
rem 这个变量会被 trans.sh 修改
set is4kn=0
if "%is4kn%"=="1" (
@ -105,6 +107,7 @@ rem 重新分区/格式化
(if "%BootType%"=="efi" (
echo select disk %DiskIndex%
rem del
echo select part 1
echo delete part override
echo select part 2
@ -112,23 +115,31 @@ rem 重新分区/格式化
echo select part 3
echo delete part override
rem 1
echo create part efi size=%EFISize%
echo format fs=fat32 quick
rem 2
echo create part msr size=16
rem 3
echo create part primary
echo format fs=ntfs quick
rem echo assign letter=Z
) else (
echo select disk %DiskIndex%
rem del
echo select part 1
rem echo delete part override
rem echo create part primary
echo delete part override
rem 1
echo create part primary
echo format fs=ntfs quick
echo active
rem echo assign letter=Z
)) > X:\diskpart.txt
rem 使用 diskpart /s ,出错不会执行剩下的 diskpart 命令
@ -140,6 +151,11 @@ rem X boot.wim (ram)
rem Y installer
rem Z os
rem 获取 BuildNumber
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v CurrentBuildNumber') do (
set "BuildNumber=%%a"
)
rem 旧版安装程序会自动在C盘设置虚拟内存新版安装程序(24h2)不会
rem 如果不创建虚拟内存1g 内存的机器安装时会报错/杀进程
if %BuildNumber% GEQ 26040 (
@ -180,11 +196,25 @@ rem 运行 ramdisk X:\setup.exe 的话
rem vista 会找不到安装源
rem server 23h2 会无法运行
rem 使用 /installfrom 可以解决?
if "%ForceOldSetup%"=="1" (
rem 有的精简版 iso install.wim 根目录没有 setup.exe
rem https://github.com/bin456789/reinstall/issues/578
if "%ForceOldSetup%"=="1" if exist Y:\sources\setup.exe (
set setup=Y:\sources\setup.exe
) else (
set setup=Y:\setup.exe
goto :SetupExeFound
)
if exist Y:\setup.exe (
set setup=Y:\setup.exe
) else if exist Y:\sources\setup.exe (
set setup=Y:\sources\setup.exe
) else if exist X:\setup.exe (
set setup=X:\setup.exe
) else (
echo "Error: setup.exe not found." >&2
exit /b 1
)
:SetupExeFound
if "%EnableUnattended%"=="1" (
set Unattended=/unattend:X:\windows.xml
@ -246,6 +276,12 @@ exit /b
rem 不要查找 Class=SCSIAdapter 因为有些驱动等号两边有空格
find /i "SCSIAdapter" "%~1" >nul
if not errorlevel 1 (
rem 有 N 种方法安装驱动
rem 1. dism /online /add-driver /driver:"%~1" # PE 不支持 /online 添加驱动
rem 2. pnputil -i -a "%~1"
rem 3. devcon
rem 4. dpinst
rem 5. drvload 官方推荐 https://learn.microsoft.com/windows-hardware/manufacture/desktop/drvload-command-line-options
drvload "%~1"
)
exit /b

View File

@ -155,7 +155,9 @@
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<ProtectYourPC>3</ProtectYourPC>
<!-- 文档说请勿使用 SkipMachineOOBE 设置自动执行 OOBE -->
<!-- 但是 Azure 的系统镜像也是用了 SkipMachineOOBE -->
<!-- https://learn.microsoft.com/windows-hardware/customize/desktop/automate-oobe -->
<SkipMachineOOBE>true</SkipMachineOOBE>
<SkipUserOOBE>true</SkipUserOOBE>
</OOBE>

View File

@ -1,36 +1,59 @@
param(
[string]$Namespace,
[string]$Class,
[string]$Namespace = "root\cimv2",
[Parameter(Mandatory = $true)] [string]$Class,
[string]$Filter,
[string]$Properties
)
$propertiesToDisplay = if ($Properties) { $Properties.Split(",") } else { @("*") }
$wmiQuery = @{
Namespace = $Namespace
Class = $Class
# 预处理属性列表:如果有输入则处理成数组,否则保持为空数组
[string[]]$propertyList = if ($Properties) {
$Properties.Split(",") | ForEach-Object { $_.Trim() }
}
else {
@()
}
if ($Filter) {
$wmiQuery.Filter = $Filter
# 检查是否支持 Get-Cimresult
$isSupportCim = [bool](Get-Command Get-Cimresult -ErrorAction SilentlyContinue)
# 构造查询参数
$queryParams = @{ Namespace = $Namespace }
if ($isSupportCim) { $queryParams.ClassName = $Class } else { $queryParams.Class = $Class }
if ($Filter) { $queryParams.Filter = $Filter }
# 限制查询属性,加快查询速度
# CIM 支持
# WIM 不支持
if ($isSupportCim -and $propertyList.Count -gt 0) {
$queryParams.Property = $propertyList
}
Get-WmiObject @wmiQuery | ForEach-Object {
$_.PSObject.Properties | Where-Object {
-not $_.Name.StartsWith("__") -and
($propertiesToDisplay -contains $_.Name -or $propertiesToDisplay -contains "*")
} | ForEach-Object {
$name = $_.Name
$value = $_.Value
# 执行查询
$results = if ($isSupportCim) { Get-Cimresult @queryParams } else { Get-WmiObject @queryParams }
# 改成 wmic 的输出格式
if ($value -is [Array]) {
$formattedValue = ($value | ForEach-Object { "`"$_`"" }) -join ","
Write-Output "$name={$formattedValue}"
}
else {
Write-Output "$name=$value"
# 遍历结果
foreach ($result in $results) {
# 遍历属性
foreach ($property in $result.PSObject.Properties) {
$name = $property.Name
$value = $property.Value
# 过滤系统属性
if ($name.StartsWith("__") -or $name -eq "CimresultProperties" -or $name -eq "CimClass") { continue }
# 只输出 propertyList 有的属性
# propertyList 为空表示不过滤
if ($propertyList.Count -eq 0 -or $propertyList -contains $name) {
# 改成 wmic 的输出格式
# 这里要注意 string 也是 IEnumerable
if ($value -isnot [string] -and $value -is [Collections.IEnumerable]) {
$formattedValue = ($value | ForEach-Object { "`"$_`"" }) -join ","
Write-Output "$name={$formattedValue}"
}
else {
Write-Output "$name=$value"
}
}
}
}