无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 485|回复: 18
打印 上一主题 下一主题

[发布] Nano11 脚本汉化版简单汉化版。。。。。。

[复制链接]
跳转到指定楼层
1#
发表于 昨天 17:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 cls822001 于 2025-9-12 17:48 编辑

Nano11 脚本汉化版。。。已测试精简出来的iso直接安装会出错。。
  1. # 检查执行策略是否为 Restricted(禁止脚本运行)
  2. if ((Get-ExecutionPolicy) -eq 'Restricted') {
  3.     Write-Host "您当前的 PowerShell 执行策略设置为 Restricted,这会阻止脚本运行。是否要将其更改为 RemoteSigned?(yes/no)"
  4.     $response = Read-Host
  5.     if ($response -eq 'yes') {
  6.         Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm:$false
  7.     } else {
  8.         Write-Host "不更改执行策略则无法运行脚本。正在退出..."
  9.         exit
  10.     }
  11. }

  12. # 检查并以管理员身份运行脚本(如果需要)
  13. $adminSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
  14. $adminGroup = $adminSID.Translate([System.Security.Principal.NTAccount])
  15. $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
  16. $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
  17. $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  18. if (! $myWindowsPrincipal.IsInRole($adminRole))
  19. {
  20.     Write-Host "将以管理员身份在新窗口中重启 nano11 镜像创建程序,您可以关闭此窗口。"
  21.     $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
  22.     $newProcess.Arguments = $myInvocation.MyCommand.Definition;
  23.     $newProcess.Verb = "runas";
  24.     [System.Diagnostics.Process]::Start($newProcess);
  25.     exit
  26. }

  27. # 开始记录日志

  28. Start-Transcript -Path "$PSScriptRoot\nano11.log"
  29. # 询问用户是否继续
  30. Write-Host "欢迎使用 nano11 构建工具!"
  31. Write-Host "此脚本生成高度精简的 Windows 11 镜像。但请注意,由于其缺乏可维护性(无法添加语言、更新或功能),它不适合常规使用。nano11 不是完整的 Windows 11 替代品,而是用于快速测试或开发的工具,可能在虚拟机环境中有用。"
  32. Write-Host  "是否要继续?(y/n)"
  33. $input = Read-Host

  34. if ($input -eq 'y') {
  35.     Write-Host "开始执行..."
  36. Start-Sleep -Seconds 3
  37. Clear-Host
  38. # 创建临时目录
  39. $mainOSDrive = $env:SystemDrive
  40. New-Item -ItemType Directory -Force -Path "$mainOSDrive\nano11\sources"
  41. # 获取 Windows 安装源路径
  42. $DriveLetter = Read-Host "请输入包含 Windows 11 镜像的驱动器盘符"
  43. $DriveLetter = $DriveLetter + ":"
  44. # 检查并转换 install.esd(如果存在)
  45. if ((Test-Path "$DriveLetter\sources\boot.wim") -eq $false -or (Test-Path "$DriveLetter\sources\install.wim") -eq $false) {
  46.     if ((Test-Path "$DriveLetter\sources\install.esd") -eq $true) {
  47.         Write-Host "找到 install.esd,正在转换为 install.wim..."
  48.         &  'dism' '/English' "/Get-WimInfo" "/wimfile:$DriveLetter\sources\install.esd"
  49.         $index = Read-Host "请输入镜像索引"
  50.         Write-Host '正在将 install.esd 转换为 install.wim。这可能需要一段时间...'
  51.         & 'DISM' /Export-Image /SourceImageFile:"$DriveLetter\sources\install.esd" /SourceIndex:$index /DestinationImageFile:"$mainOSDrive\nano11\sources\install.wim" /Compress:max /CheckIntegrity
  52.     } else {
  53.         Write-Host "在指定驱动器盘符中找不到 Windows 安装文件。正在退出。"
  54.         exit
  55.     }
  56. }

  57. # 复制 Windows 镜像
  58. Write-Host "正在复制 Windows 镜像..."
  59. Copy-Item -Path "$DriveLetter\*" -Destination "$mainOSDrive\nano11" -Recurse -Force > null
  60. Remove-Item "$mainOSDrive\nano11\sources\install.esd" -ErrorAction SilentlyContinue

  61. # 获取镜像信息并挂载
  62. Write-Host "获取镜像信息:"
  63. &  'dism' '/English' "/Get-WimInfo" "/wimfile:$mainOSDrive\nano11\sources\install.wim"
  64. $index = Read-Host "请输入镜像索引"
  65. Write-Host "正在挂载 Windows 镜像。这可能需要一段时间。"
  66. $wimFilePath = "$($env:SystemDrive)\nano11\sources\install.wim"
  67. & takeown "/F" $wimFilePath
  68. & icacls $wimFilePath "/grant" "$($adminGroup.Value):(F)"
  69. try {
  70.     Set-ItemProperty -Path $wimFilePath -Name IsReadOnly -Value $false -ErrorAction Stop
  71. } catch {
  72. # 忽略错误
  73. }
  74. New-Item -ItemType Directory -Force -Path "$mainOSDrive\scratchdir"
  75. & dism /English "/mount-image" "/imagefile:$($env:SystemDrive)\nano11\sources\install.wim" "/index:$index" "/mountdir:$($env:SystemDrive)\scratchdir"

  76. # --- 主动获取目标文件夹所有权 ---
  77. $scratchDir = "$($env:SystemDrive)\scratchdir"
  78. $foldersToOwn = @( "$scratchDir\Windows\System32\DriverStore\FileRepository", "$scratchDir\Windows\Fonts", "$scratchDir\Windows\Web", "$scratchDir\Windows\Help", "$scratchDir\Windows\Cursors", "$scratchDir\Program Files (x86)\Microsoft", "$scratchDir\Program Files\WindowsApps", "$scratchDir\Windows\System32\Microsoft-Edge-Webview", "$scratchDir\Windows\System32\Recovery", "$scratchDir\Windows\WinSxS", "$scratchDir\Windows\assembly", "$scratchDir\ProgramData\Microsoft\Windows Defender", "$scratchDir\Windows\System32\InputMethod", "$scratchDir\Windows\Speech", "$scratchDir\Windows\Temp" )
  79. $filesToOwn = @( "$scratchDir\Windows\System32\OneDriveSetup.exe" )
  80. foreach ($folder in $foldersToOwn) { if (Test-Path $folder) { Write-Host "正在获取文件夹所有权: $folder"; & takeown.exe /F $folder /R /D Y ; & icacls.exe $folder /grant "$($adminGroup.Value):(F)" /T /C  } }
  81. foreach ($file in $filesToOwn) { if (Test-Path $file) { Write-Host "正在获取文件所有权: $file"; & takeown.exe /F $file /D Y ; & icacls.exe $file /grant "$($adminGroup.Value):(F)" /C  } }
  82. # 获取系统默认语言
  83. $imageIntl = & dism /English /Get-Intl "/Image:$scratchDir"
  84. $languageLine = $imageIntl -split '\n' | Where-Object { $_ -match 'Default system UI language : ([a-zA-Z]{2}-[a-zA-Z]{2})' }
  85. if ($languageLine) { $languageCode = $Matches[1]; Write-Host "默认系统界面语言代码: $languageCode" } else { Write-Host "未找到默认系统界面语言代码。" }
  86. # 获取系统架构
  87. $imageInfo = & 'dism' '/English' '/Get-WimInfo' "/wimFile:$wimFilePath" "/index:$index"
  88. $lines = $imageInfo -split '\r?\n'
  89. foreach ($line in $lines) { if ($line -like '*Architecture : *') { $architecture = $line -replace 'Architecture : ',''; if ($architecture -eq 'x64') { $architecture = 'amd64' }; Write-Host "系统架构: $architecture"; break } }
  90. if (-not $architecture) { Write-Host "未找到架构信息。" }
  91. # 移除预装应用 (AppX)
  92. Write-Host "正在移除预装的 AppX 包 (臃肿软件)..."
  93. $packagesToRemove = Get-AppxProvisionedPackage -Path $scratchDir | Where-Object { $_.PackageName -like '*Zune*' -or $_.PackageName -like '*Bing*' -or $_.PackageName -like '*Clipchamp*' -or $_.PackageName -like '*Gaming*' -or $_.PackageName -like '*People*' -or $_.PackageName -like '*PowerAutomate*' -or $_.PackageName -like '*Teams*' -or $_.PackageName -like '*Todos*' -or $_.PackageName -like '*YourPhone*' -or $_.PackageName -like '*SoundRecorder*' -or $_.PackageName -like '*Solitaire*' -or $_.PackageName -like '*FeedbackHub*' -or $_.PackageName -like '*Maps*' -or $_.PackageName -like '*OfficeHub*' -or $_.PackageName -like '*Help*' -or $_.PackageName -like '*Family*' -or $_.PackageName -like '*Alarms*' -or $_.PackageName -like '*CommunicationsApps*' -or $_.PackageName -like '*Copilot*' -or $_.PackageName -like '*CompatibilityEnhancements*' -or $_.PackageName -like '*AV1VideoExtension*' -or $_.PackageName -like '*AVCEncoderVideoExtension*' -or $_.PackageName -like '*HEIFImageExtension*' -or $_.PackageName -like '*HEVCVideoExtension*' -or $_.PackageName -like '*MicrosoftStickyNotes*' -or $_.PackageName -like '*OutlookForWindows*' -or $_.PackageName -like '*RawImageExtension*' -or $_.PackageName -like '*SecHealthUI*' -or $_.PackageName -like '*VP9VideoExtensions*' -or $_.PackageName -like '*WebpImageExtension*' -or $_.PackageName -like '*DevHome*' -or $_.PackageName -like '*Photos*' -or $_.PackageName -like '*Camera*' -or $_.PackageName -like '*QuickAssist*' -or $_.PackageName -like '*CoreAI*'  -or $_.PackageName -like '*PeopleExperienceHost*' -or $_.PackageName -like '*PinningConfirmationDialog*' -or $_.PackageName -like '*SecureAssessmentBrowser*' -or $_.PackageName -like '*Paint*' -or $_.PackageName -like '*Notepad*'  }
  94. foreach ($package in $packagesToRemove) { write-host "正在移除: $($package.DisplayName)"; Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $package.PackageName }
  95. # 清理残留文件
  96. Write-Host "尝试移除残留的 WindowsApps 文件夹..."
  97. foreach ($package in $packagesToRemove) { $folderPath = Join-Path "$scratchDir\Program Files\WindowsApps" $package.PackageName; if (Test-Path $folderPath) { Write-Host "正在删除文件夹: $($package.PackageName)"; Remove-Item $folderPath -Recurse -Force -ErrorAction SilentlyContinue } }

  98. Write-Host "系统应用移除完成!现在开始移除系统功能包..."
  99. Start-Sleep -Seconds 1
  100. Clear-Host

  101. # 移除系统功能包
  102. $scratchDir = "$($env:SystemDrive)\scratchdir"
  103. $packagePatterns = @(
  104.      # --- 旧版组件和可选应用 ---
  105.     "Microsoft-Windows-InternetExplorer-Optional-Package~",
  106.     "Microsoft-Windows-MediaPlayer-Package~",
  107.     "Microsoft-Windows-WordPad-FoD-Package~",
  108.     "Microsoft-Windows-StepsRecorder-Package~",
  109.     "Microsoft-Windows-MSPaint-FoD-Package~",
  110.     "Microsoft-Windows-SnippingTool-FoD-Package~",
  111.     "Microsoft-Windows-TabletPCMath-Package~",
  112.     "Microsoft-Windows-Xps-Xps-Viewer-Opt-Package~",
  113.     "Microsoft-Windows-PowerShell-ISE-FOD-Package~",
  114.     "OpenSSH-Client-Package~",

  115.       # --- 语言和输入功能(仅保留主语言)---
  116.     "Microsoft-Windows-LanguageFeatures-Handwriting-$languageCode-Package~",
  117.     "Microsoft-Windows-LanguageFeatures-OCR-$languageCode-Package~",
  118.     "Microsoft-Windows-LanguageFeatures-Speech-$languageCode-Package~",
  119.     "Microsoft-Windows-LanguageFeatures-TextToSpeech-$languageCode-Package~",
  120.     "*IME-ja-jp*",
  121.     "*IME-ko-kr*",
  122.     "*IME-zh-cn*",
  123.     "*IME-zh-tw*",

  124.      # --- 核心操作系统功能(破坏性移除)---
  125.     "Windows-Defender-Client-Package~",
  126.     "Microsoft-Windows-Search-Engine-Client-Package~",
  127.     "Microsoft-Windows-Kernel-LA57-FoD-Package~",

  128.         # --- 安全与身份(会破坏功能)---
  129.     "Microsoft-Windows-Hello-Face-Package~",
  130.     "Microsoft-Windows-Hello-BioEnrollment-Package~",
  131.     "Microsoft-Windows-BitLocker-DriveEncryption-FVE-Package~",
  132.     "Microsoft-Windows-TPM-WMI-Provider-Package~",

  133.         # --- 辅助工具 ---
  134.     "Microsoft-Windows-Narrator-App-Package~",
  135.     "Microsoft-Windows-Magnifier-App-Package~",
  136.         # --- 其他功能 ---
  137.     "Microsoft-Windows-Printing-PMCPPC-FoD-Package~",
  138.     "Microsoft-Windows-WebcamExperience-Package~",
  139.     "Microsoft-Media-MPEG2-Decoder-Package~",
  140.     "Microsoft-Windows-Wallpaper-Content-Extended-FoD-Package~"
  141. )

  142. $allPackages = & dism /image:$scratchDir /Get-Packages /Format:Table
  143. $allPackages = $allPackages -split "`n" | Select-Object -Skip 1

  144. foreach ($packagePattern in $packagePatterns) {
  145.     # Filter the packages to remove
  146.     $packagesToRemove = $allPackages | Where-Object { $_ -like "$packagePattern*" }

  147.     foreach ($package in $packagesToRemove) {
  148.         # Extract the package identity
  149.         $packageIdentity = ($package -split "\s+")[0]

  150.         Write-Host "正在移除 $packageIdentity..."
  151.         & dism /image:$scratchDir /Remove-Package /PackageName:$packageIdentity
  152.     }
  153. }
  154.     # 移除预编译的 .NET 程序集
  155.     Write-Host "正在移除预编译的 .NET 程序集 (本机映像)..."
  156. Remove-Item -Path "$scratchDir\Windows\assembly\NativeImages_*" -Recurse -Force -ErrorAction SilentlyContinue
  157.     # 手动删除文件
  158.     Write-Host "正在进行彻底的手动文件删除..."
  159. $winDir = "$scratchDir\Windows"
  160.     # 精简驱动程序存储
  161.     Write-Host "正在精简 DriverStore... (移除非必要驱动程序)"
  162. $driverRepo = Join-Path -Path $winDir -ChildPath "System32\DriverStore\FileRepository"
  163. $patternsToRemove = @(
  164.     'prn*',      # Printer drivers (e.g., prnms001.inf, prnge001.inf)
  165.     'scan*',     # Scanner drivers
  166.     'mfd*',      # Multi-function device drivers
  167.     'wscsmd.inf*', # Smartcard readers
  168.     'tapdrv*',   # Tape drives
  169.     'rdpbus.inf*', # Remote Desktop virtual bus
  170.     'tdibth.inf*'  # Bluetooth Personal Area Network
  171. )

  172. #获取所有驱动程序包并删除匹配模式的驱动程序包
  173. Get-ChildItem -Path $driverRepo -Directory | ForEach-Object {
  174.     $driverFolder = $_.Name
  175.     foreach ($pattern in $patternsToRemove) {
  176.         if ($driverFolder -like $pattern) {
  177.             Write-Host "正在移除非必要驱动程序包: $driverFolder"
  178.             Remove-Item -Path $_.FullName -Recurse -Force
  179.             break # Move to the next folder once a match is found
  180.         }
  181.     }
  182. }
  183. # 精简字体
  184. $fontsPath = Join-Path -Path $winDir -ChildPath "Fonts"
  185. if (Test-Path $fontsPath) { Get-ChildItem -Path $fontsPath -Exclude "segoe*.*", "tahoma*.*", "marlett.ttf", "8541oem.fon", "segui*.*", "consol*.*", "lucon*.*", "calibri*.*", "arial*.*", "times*.*", "cou*.*", "8*.*" | Remove-Item -Recurse -Force; Get-ChildItem -Path $fontsPath -Include "mingli*", "msjh*", "msyh*", "malgun*", "meiryo*", "yugoth*", "segoeuihistoric.ttf" | Remove-Item -Recurse -Force }
  186. # 移除其他组件
  187. Remove-Item -Path (Join-Path -Path $winDir -ChildPath "Speech\Engines\TTS") -Recurse -Force -ErrorAction SilentlyContinue
  188. Remove-Item -Path "$scratchDir\ProgramData\Microsoft\Windows Defender\Definition Updates" -Recurse -Force -ErrorAction SilentlyContinue
  189. Remove-Item -Path "$scratchDir\Windows\System32\InputMethod\CHS" -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path "$scratchDir\Windows\System32\InputMethod\CHT" -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path "$scratchDir\Windows\System32\InputMethod\JPN" -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path "$scratchDir\Windows\System32\InputMethod\KOR" -Recurse -Force -ErrorAction SilentlyContinue
  190. Remove-Item -Path "$scratchDir\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
  191. Remove-Item -Path (Join-Path -Path $winDir -ChildPath "Web") -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path (Join-Path -Path $winDir -ChildPath "Help") -Recurse -Force -ErrorAction SilentlyContinue; Remove-Item -Path (Join-Path -Path $winDir -ChildPath "Cursors") -Recurse -Force -ErrorAction SilentlyContinue
  192. # 移除 Edge, WinRE 和 OneDrive
  193. Write-Host "正在移除 Edge、WinRE 和 OneDrive..."
  194. Remove-Item -Path "$scratchDir\Program Files (x86)\Microsoft\Edge*" -Recurse -Force
  195. if ($architecture -eq 'amd64') { $folderPath = Get-ChildItem -Path "$scratchDir\Windows\WinSxS" -Filter "amd64_microsoft-edge-webview_31bf3856ad364e35*" -Directory | Select-Object -ExpandProperty FullName }
  196. if ($folderPath) { Remove-Item -Path $folderPath -Recurse -Force  }
  197. Remove-Item -Path "$scratchDir\Windows\System32\Microsoft-Edge-Webview" -Recurse -Force
  198. Remove-Item -Path "$scratchDir\Windows\System32\Recovery\winre.wim" -Recurse -Force
  199. New-Item -Path "$scratchDir\Windows\System32\Recovery\winre.wim" -ItemType File -Force
  200. Remove-Item -Path "$scratchDir\Windows\System32\OneDriveSetup.exe" -Force
  201. # 清理镜像
  202. & 'dism' '/English' "/image:$scratchDir" '/Cleanup-Image' '/StartComponentCleanup' '/ResetBase'

  203. # 处理 WinSxS 文件夹
  204. Write-Host "正在获取 WinSxS 文件夹所有权。这可能需要一段时间..."
  205. & 'takeown' '/f' "$mainOSDrive\scratchdir\Windows\WinSxS" '/r'
  206. & 'icacls' "$mainOSDrive\scratchdir\Windows\WinSxS" '/grant' "$($adminGroup.Value):(F)" '/T' '/C'
  207. Write-host "完成!"
  208. # 创建精简版 WinSxS
  209. $folderPath = Join-Path -Path $mainOSDrive -ChildPath "\scratchdir\Windows\WinSxS_edit"
  210. $sourceDirectory = "$mainOSDrive\scratchdir\Windows\WinSxS"
  211. $destinationDirectory = "$mainOSDrive\scratchdir\Windows\WinSxS_edit"
  212. New-Item -Path $folderPath -ItemType Directory
  213. # 根据架构复制必要文件
  214. if ($architecture -eq "amd64") {
  215.    $dirsToCopy = @(
  216.         "x86_microsoft.windows.common-controls_6595b64144ccf1df_*",
  217.         "x86_microsoft.windows.gdiplus_6595b64144ccf1df_*",   
  218.         "x86_microsoft.windows.i..utomation.proxystub_6595b64144ccf1df_*",
  219.         "x86_microsoft.windows.isolationautomation_6595b64144ccf1df_*",
  220.         "x86_microsoft-windows-s..ngstack-onecorebase_31bf3856ad364e35_*",
  221.         "x86_microsoft-windows-s..stack-termsrv-extra_31bf3856ad364e35_*",
  222.         "x86_microsoft-windows-servicingstack_31bf3856ad364e35_*",
  223.         "x86_microsoft-windows-servicingstack-inetsrv_*",
  224.         "x86_microsoft-windows-servicingstack-onecore_*",
  225.         "amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_*",
  226.         "amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_*",
  227.         "amd64_microsoft.windows.c..-controls.resources_6595b64144ccf1df_*",
  228.         "amd64_microsoft.windows.common-controls_6595b64144ccf1df_*",
  229.         "amd64_microsoft.windows.gdiplus_6595b64144ccf1df_*",
  230.         "amd64_microsoft.windows.i..utomation.proxystub_6595b64144ccf1df_*",
  231.         "amd64_microsoft.windows.isolationautomation_6595b64144ccf1df_*",
  232.         "amd64_microsoft-windows-s..stack-inetsrv-extra_31bf3856ad364e35_*",
  233.         "amd64_microsoft-windows-s..stack-msg.resources_31bf3856ad364e35_*",
  234.         "amd64_microsoft-windows-s..stack-termsrv-extra_31bf3856ad364e35_*",
  235.         "amd64_microsoft-windows-servicingstack_31bf3856ad364e35_*",
  236.         "amd64_microsoft-windows-servicingstack-inetsrv_31bf3856ad364e35_*",
  237.         "amd64_microsoft-windows-servicingstack-msg_31bf3856ad364e35_*",
  238.         "amd64_microsoft-windows-servicingstack-onecore_31bf3856ad364e35_*",
  239.         "Catalogs",
  240.         "FileMaps",
  241.         "Fusion",
  242.         "InstallTemp",
  243.         "Manifests",
  244.         "x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_*",
  245.         "x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_*",
  246.         "x86_microsoft.windows.c..-controls.resources_6595b64144ccf1df_*",
  247.         "x86_microsoft.windows.c..-controls.resources_6595b64144ccf1df_*"
  248.     )
  249. # Copy each directory
  250.    foreach ($dir in $dirsToCopy) {
  251.         $sourceDirs = Get-ChildItem -Path $sourceDirectory -Filter $dir -Directory
  252.         foreach ($sourceDir in $sourceDirs) {
  253.             $destDir = Join-Path -Path $destinationDirectory -ChildPath $sourceDir.Name
  254.             Write-Host "Copying $sourceDir.FullName to $destDir"
  255.             Copy-Item -Path $sourceDir.FullName -Destination $destDir -Recurse -Force
  256.         }
  257.     }
  258. }
  259. elseif ($architecture -eq "arm64") {
  260.      $dirsToCopy = @(
  261.         "arm64_microsoft-windows-servicingstack-onecore_31bf3856ad364e35_*",
  262.         "Catalogs"
  263.         "FileMaps"
  264.         "Fusion"
  265.         "InstallTemp"
  266.         "Manifests"
  267.         "SettingsManifests"
  268.         "Temp"
  269.         "x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_*"
  270.         "x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_*"
  271.         "x86_microsoft.windows.c..-controls.resources_6595b64144ccf1df_*"
  272.         "x86_microsoft.windows.common-controls_6595b64144ccf1df_*"
  273.         "x86_microsoft.windows.gdiplus_6595b64144ccf1df_*"
  274.         "x86_microsoft.windows.i..utomation.proxystub_6595b64144ccf1df_*"
  275.         "x86_microsoft.windows.isolationautomation_6595b64144ccf1df_*"
  276.         "arm_microsoft.windows.c..-controls.resources_6595b64144ccf1df_*"
  277.         "arm_microsoft.windows.common-controls_6595b64144ccf1df_*"
  278.         "arm_microsoft.windows.gdiplus_6595b64144ccf1df_*"
  279.         "arm_microsoft.windows.i..utomation.proxystub_6595b64144ccf1df_*"
  280.         "arm_microsoft.windows.isolationautomation_6595b64144ccf1df_*"
  281.         "arm64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_*"
  282.         "arm64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_*"
  283.         "arm64_microsoft.windows.c..-controls.resources_6595b64144ccf1df_*"
  284.         "arm64_microsoft.windows.common-controls_6595b64144ccf1df_*"
  285.         "arm64_microsoft.windows.gdiplus_6595b64144ccf1df_*"
  286.         "arm64_microsoft.windows.i..utomation.proxystub_6595b64144ccf1df_*"
  287.         "arm64_microsoft.windows.isolationautomation_6595b64144ccf1df_*"
  288.         "arm64_microsoft-windows-servicing-adm_31bf3856ad364e35_*"
  289.         "arm64_microsoft-windows-servicingcommon_31bf3856ad364e35_*"
  290.         "arm64_microsoft-windows-servicing-onecore-uapi_31bf3856ad364e35_*"
  291.         "arm64_microsoft-windows-servicingstack_31bf3856ad364e35_*"
  292.         "arm64_microsoft-windows-servicingstack-inetsrv_31bf3856ad364e35_*"
  293.         "arm64_microsoft-windows-servicingstack-msg_31bf3856ad364e35_*"
  294.     )
  295. }
  296. foreach ($dir in $dirsToCopy) {
  297.         $sourceDirs = Get-ChildItem -Path $sourceDirectory -Filter $dir -Directory
  298.         foreach ($sourceDir in $sourceDirs) {
  299.             $destDir = Join-Path -Path $destinationDirectory -ChildPath $sourceDir.Name
  300.             Write-Host "正在复制 $sourceDir.FullName 到 $destDir"
  301.             Copy-Item -Path $sourceDir.FullName -Destination $destDir -Recurse -Force
  302.         }
  303.     }  

  304. # 替换 WinSxS 文件夹
  305. Write-Host "正在删除原 WinSxS。这可能需要一段时间..."
  306.         Remove-Item -Path $mainOSDrive\scratchdir\Windows\WinSxS -Recurse -Force

  307. Rename-Item -Path $mainOSDrive\scratchdir\Windows\WinSxS_edit -NewName $mainOSDrive\scratchdir\Windows\WinSxS
  308. Write-Host "完成!"
  309. # 加载注册表配置单元进行修改
  310. reg load HKLM\zCOMPONENTS $ScratchDisk\scratchdir\Windows\System32\config\COMPONENTS | Out-Null
  311. reg load HKLM\zDEFAULT $ScratchDisk\scratchdir\Windows\System32\config\default | Out-Null
  312. reg load HKLM\zNTUSER $ScratchDisk\scratchdir\Users\Default\ntuser.dat | Out-Null
  313. reg load HKLM\zSOFTWARE $ScratchDisk\scratchdir\Windows\System32\config\SOFTWARE | Out-Null
  314. reg load HKLM\zSYSTEM $ScratchDisk\scratchdir\Windows\System32\config\SYSTEM | Out-Null
  315. # 绕过系统要求
  316. Write-Host "正在绕过系统要求(在系统镜像上):"
  317. & 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV1' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  318. & 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV2' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  319. & 'reg' 'add' 'HKLM\zNTUSER\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV1' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  320. & 'reg' 'add' 'HKLM\zNTUSER\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV2' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  321. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassCPUCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  322. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassRAMCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  323. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassSecureBootCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  324. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassStorageCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  325. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassTPMCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  326. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\MoSetup' '/v' 'AllowUpgradesWithUnsupportedTPMOrCPU' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  327. # 禁用推广应用
  328. Write-Host "正在禁用推广应用:"
  329. & 'reg' 'add' 'HKLM\zNTUSER\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'OemPreInstalledAppsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  330. & 'reg' 'add' 'HKLM\zNTUSER\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'PreInstalledAppsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  331. & 'reg' 'add' 'HKLM\zNTUSER\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SilentInstalledAppsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  332. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\CloudContent' '/v' 'DisableWindowsConsumerFeatures' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  333. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'ContentDeliveryAllowed' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  334. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\PolicyManager\current\device\Start' '/v' 'ConfigureStartPins' '/t' 'REG_SZ' '/d' '{"pinnedList": [{}]}' '/f' | Out-Null
  335. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'ContentDeliveryAllowed' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  336. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'ContentDeliveryAllowed' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  337. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'FeatureManagementEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  338. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'OemPreInstalledAppsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  339. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'PreInstalledAppsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  340. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'PreInstalledAppsEverEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  341. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SilentInstalledAppsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  342. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SoftLandingEnabled' '/t' 'REG_DWORD' '/d' '0' '/f'| Out-Null
  343. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContentEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  344. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContent-310093Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  345. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContent-338388Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  346. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContent-338389Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  347. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContent-338393Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  348. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContent-353694Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  349. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContent-353696Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  350. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SubscribedContentEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  351. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager' '/v' 'SystemPaneSuggestionsEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  352. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\PushToInstall' '/v' 'DisablePushToInstall' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  353. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\MRT' '/v' 'DontOfferThroughWUAU' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  354. & 'reg' 'delete' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager\Subscriptions' '/f' | Out-Null
  355. & 'reg' 'delete' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager\SuggestedApps' '/f' | Out-Null
  356. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\CloudContent' '/v' 'DisableConsumerAccountStateContent' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  357. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\CloudContent' '/v' 'DisableCloudOptimizedContent' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  358. Write-Host "在 OOBE 中启用本地账户:"
  359. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\OOBE' '/v' 'BypassNRO' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  360. Copy-Item -Path "$PSScriptRoot\autounattend.xml" -Destination "$ScratchDisk\scratchdir\Windows\System32\Sysprep\autounattend.xml" -Force | Out-Null
  361. Write-Host "禁用保留存储:"
  362. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager' '/v' 'ShippedWithReserves' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  363. Write-Host "禁用BitLocker设备加密"
  364. & 'reg' 'add' 'HKLM\zSYSTEM\ControlSet001\Control\BitLocker' '/v' 'PreventDeviceEncryption' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  365. Write-Host "禁用聊天图标:"
  366. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\Windows Chat' '/v' 'ChatIcon' '/t' 'REG_DWORD' '/d' '3' '/f' | Out-Null
  367. & 'reg' 'add' 'HKLM\zNTUSER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced' '/v' 'TaskbarMn' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  368. Write-Host "移除 Edge 相关注册表项"
  369. reg delete "HKEY_LOCAL_MACHINE\zSOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge" /f | Out-Null
  370. reg delete "HKEY_LOCAL_MACHINE\zSOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update" /f | Out-Null
  371. Write-Host "禁用 OneDrive 文件夹备份"
  372. & 'reg' 'add' "HKLM\zSOFTWARE\Policies\Microsoft\Windows\OneDrive" '/v' 'DisableFileSyncNGSC' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  373. Write-Host "禁用遥测:"
  374. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo' '/v' 'Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  375. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Windows\CurrentVersion\Privacy' '/v' 'TailoredExperiencesWithDiagnosticDataEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  376. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Speech_OneCore\Settings\OnlineSpeechPrivacy' '/v' 'HasAccepted' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  377. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Input\TIPC' '/v' 'Enabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  378. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\InputPersonalization' '/v' 'RestrictImplicitInkCollection' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  379. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\InputPersonalization' '/v' 'RestrictImplicitTextCollection' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  380. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\InputPersonalization\TrainedDataStore' '/v' 'HarvestContacts' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  381. & 'reg' 'add' 'HKLM\zNTUSER\Software\Microsoft\Personalization\Settings' '/v' 'AcceptedPrivacyPolicy' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  382. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\DataCollection' '/v' 'AllowTelemetry' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  383. & 'reg' 'add' 'HKLM\zSYSTEM\ControlSet001\Services\dmwappushservice' '/v' 'Start' '/t' 'REG_DWORD' '/d' '4' '/f' | Out-Null
  384. Write-Host "阻止安装 DevHome 和 Outlook:"
  385. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Orchestrator\UScheduler\OutlookUpdate' '/v' 'workCompleted' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  386. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Orchestrator\UScheduler\DevHomeUpdate' '/v' 'workCompleted' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  387. & 'reg' 'delete' 'HKLM\zSOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\OutlookUpdate' '/f' | Out-Null
  388. & 'reg' 'delete' 'HKLM\zSOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\DevHomeUpdate' '/f' | Out-Null
  389. Write-Host "禁用Copilot"
  390. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsCopilot' '/v' 'TurnOffWindowsCopilot' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  391. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Edge' '/v' 'HubsSidebarEnabled' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  392. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\Explorer' '/v' 'DisableSearchBoxSuggestions' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  393. Write-Host "禁用Teams:"
  394. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Teams' '/v' 'DisableInstallation' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  395. Write-Host "禁用 New Outlook":
  396. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\Windows Mail' '/v' 'PreventRun' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  397. $tasksPath = "C:\scratchdir\Windows\System32\Tasks"

  398. Write-Host "删除计划任务定义文件..."

  399. # Application Compatibility Appraiser
  400. Remove-Item -Path "$tasksPath\Microsoft\Windows\Application Experience\Microsoft Compatibility Appraiser" -Force -ErrorAction SilentlyContinue

  401. # Customer Experience Improvement Program (removes the entire folder and all tasks within it)
  402. Remove-Item -Path "$tasksPath\Microsoft\Windows\Customer Experience Improvement Program" -Recurse -Force -ErrorAction SilentlyContinue

  403. # Program Data Updater
  404. Remove-Item -Path "$tasksPath\Microsoft\Windows\Application Experience\ProgramDataUpdater" -Force -ErrorAction SilentlyContinue

  405. # Chkdsk Proxy
  406. Remove-Item -Path "$tasksPath\Microsoft\Windows\Chkdsk\Proxy" -Force -ErrorAction SilentlyContinue

  407. # Windows Error Reporting (QueueReporting)
  408. Remove-Item -Path "$tasksPath\Microsoft\Windows\Windows Error Reporting\QueueReporting" -Force -ErrorAction SilentlyContinue

  409. Write-Host "任务文件已删除。"
  410. Write-Host "禁用 Windows 更新..."
  411. & 'reg' 'add' "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" '/v' 'StopWUPostOOBE1' '/t' 'REG_SZ' '/d' 'net stop wuauserv' '/f'
  412. & 'reg' 'add' "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" '/v' 'StopWUPostOOBE2' '/t' 'REG_SZ' '/d' 'sc stop wuauserv' '/f'
  413. & 'reg' 'add' "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" '/v' 'StopWUPostOOBE3' '/t' 'REG_SZ' '/d' 'sc config wuauserv start= disabled' '/f'
  414. & 'reg' 'add' "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" '/v' 'DisbaleWUPostOOBE1' '/t' 'REG_SZ' '/d' 'reg add HKLM\SYSTEM\CurrentControlSet\Services\wuauserv /v Start /t REG_DWORD /d 4 /f' '/f'
  415. & 'reg' 'add' "HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" '/v' 'DisbaleWUPostOOBE2' '/t' 'REG_SZ' '/d' 'reg add HKLM\SYSTEM\ControlSet001\Services\wuauserv /v Start /t REG_DWORD /d 4 /f' '/f'
  416. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' '/v' 'DoNotConnectToWindowsUpdateInternetLocations' '/t' 'REG_DWORD' '/d' '1' '/f'
  417. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' '/v' 'DisableWindowsUpdateAccess' '/t' 'REG_DWORD' '/d' '1' '/f'
  418. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' '/v' 'WUServer' '/t' 'REG_SZ' '/d' 'localhost' '/f'
  419. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' '/v' 'WUStatusServer' '/t' 'REG_SZ' '/d' 'localhost' '/f'
  420. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate' '/v' 'UpdateServiceUrlAlternate' '/t' 'REG_SZ' '/d' 'localhost' '/f'
  421. & 'reg' 'add' 'HKLM\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' '/v' 'UseWUServer' '/t' 'REG_DWORD' '/d' '1' '/f'
  422. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\OOBE' '/v' 'DisableOnline' '/t' 'REG_DWORD' '/d' '1' '/f'
  423. & 'reg' 'add' 'HKLM\zSYSTEM\ControlSet001\Services\wuauserv' '/v' 'Start' '/t' 'REG_DWORD' '/d' '4' '/f'
  424. & 'reg' 'delete' 'HKLM\zSYSTEM\ControlSet001\Services\WaaSMedicSVC' '/f'
  425. & 'reg' 'delete' 'HKLM\zSYSTEM\ControlSet001\Services\UsoSvc' '/f'
  426. & 'reg' 'add' 'HKEY_LOCAL_MACHINE\zSOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU' '/v' 'NoAutoUpdate' '/t' 'REG_DWORD' '/d' '1' '/f'
  427. Write-Host "禁用 Windows Defender"
  428. $servicePaths = @(
  429.     "WinDefend",
  430.     "WdNisSvc",
  431.     "WdNisDrv",
  432.     "WdFilter",
  433.     "Sense"
  434. )

  435. foreach ($path in $servicePaths) {
  436.     Set-ItemProperty -Path "HKLM:\zSYSTEM\ControlSet001\Services\$path" -Name "Start" -Value 4
  437. }
  438. & 'reg' 'add' 'HKLM\zSOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' '/v' 'SettingsPageVisibility' '/t' 'REG_SZ' '/d' 'hide:virus;windowsupdate' '/f'
  439. Write-Host "优化完成!"
  440. Write-Host "卸载注册表..."
  441. reg unload HKLM\zCOMPONENTS >null
  442. reg unload HKLM\zDEFAULT >null
  443. reg unload HKLM\zNTUSER >null
  444. reg unload HKLM\zSOFTWARE
  445. reg unload HKLM\zSYSTEM >null

  446. Write-Host "加载注册表配置单元以移除服务..."
  447. reg load HKLM\zSYSTEM "$scratchDir\Windows\System32\config\SYSTEM" | Out-Null
  448. $servicesToRemove = @(
  449.     'Spooler',
  450.     'PrintNotify',
  451.     'Fax',
  452.     'RemoteRegistry',
  453.     'diagsvc',
  454.     'WerSvc',
  455.     'PcaSvc',
  456.     #'DPS',
  457.     # 'Audiosrv', # CRITICAL: Removing this is a likely cause of boot failure.
  458.     # 'AudioEndpointBuilder', # CRITICAL: Dependency for Audiosrv.
  459.     'MapsBroker',
  460.     'WalletService',
  461.     'BthAvctpSvc',
  462.     'BluetoothUserService',
  463.     # 'WbioSrvc', # RISKY: Can cause logon screen to hang.
  464.     'wuauserv',
  465.     'UsoSvc',
  466.     'WaaSMedicSvc'
  467. )
  468. foreach ($service in $servicesToRemove) { Write-Host "正在移除服务: $service"; & 'reg' 'delete' "HKLM\zSYSTEM\ControlSet001\Services\$service" /f | Out-Null }
  469. reg unload HKLM\zSYSTEM

  470. Write-Host "清理并卸载 install.wim..."
  471. & 'dism' '/English' "/image:$scratchDir" '/Cleanup-Image' '/StartComponentCleanup' '/ResetBase'
  472. & 'dism' '/English' '/unmount-image' "/mountdir:$scratchDir" '/commit'
  473. & 'dism' '/English' '/Export-Image' "/SourceImageFile:$mainOSDrive\nano11\sources\install.wim" "/SourceIndex:$index" "/DestinationImageFile:$mainOSDrive\nano11\sources\install2.wim" '/compress:max'
  474. Remove-Item -Path "$mainOSDrive\nano11\sources\install.wim" -Force
  475. Rename-Item -Path "$mainOSDrive\nano11\sources\install2.wim" -NewName "install.wim"

  476. Write-Host "精简 boot.wim..."
  477. $bootWimPath = "$($env:SystemDrive)\nano11\sources\boot.wim"
  478. Write-Host "获取 $bootWimPath 的所有权..."
  479. & takeown "/F" $bootWimPath
  480. & icacls $bootWimPath "/grant" "$($adminGroup.Value):(F)"
  481. try {
  482.     Set-ItemProperty -Path $bootWimPath -Name IsReadOnly -Value $false -ErrorAction Stop
  483. } catch {
  484. }
  485. Write-Host "从 boot.wim 导出修改后的安装镜像 (索引 2)..."
  486. $newBootWimPath = "$($env:SystemDrive)\nano11\sources\boot_new.wim"
  487. $finalBootWimPath = "$($env:SystemDrive)\nano11\sources\boot_final.wim"
  488. & 'dism' '/English' '/Export-Image' "/SourceImageFile:$bootWimPath" '/SourceIndex:2' "/DestinationImageFile:$newBootWimPath"
  489. & 'dism' '/English' '/mount-image' "/imagefile:$newbootWimPath" '/index:1' "/mountdir:$scratchDir"
  490. reg load HKLM\zDEFAULT $ScratchDisk\scratchdir\Windows\System32\config\default | Out-Null
  491. reg load HKLM\zNTUSER $ScratchDisk\scratchdir\Users\Default\ntuser.dat | Out-Null
  492. reg load HKLM\zSOFTWARE $ScratchDisk\scratchdir\Windows\System32\config\SOFTWARE | Out-Null
  493. reg load HKLM\zSYSTEM $ScratchDisk\scratchdir\Windows\System32\config\SYSTEM | Out-Null
  494. Write-Host "绕过系统要求(在安装镜像上):"
  495. & 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV1' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  496. & 'reg' 'add' 'HKLM\zDEFAULT\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV2' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  497. & 'reg' 'add' 'HKLM\zNTUSER\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV1' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  498. & 'reg' 'add' 'HKLM\zNTUSER\Control Panel\UnsupportedHardwareNotificationCache' '/v' 'SV2' '/t' 'REG_DWORD' '/d' '0' '/f' | Out-Null
  499. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassCPUCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  500. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassRAMCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  501. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassSecureBootCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  502. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassStorageCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  503. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\LabConfig' '/v' 'BypassTPMCheck' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  504. & 'reg' 'add' 'HKLM\zSYSTEM\Setup\MoSetup' '/v' 'AllowUpgradesWithUnsupportedTPMOrCPU' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  505. Write-Host "禁用 BitLocker 设备加密"
  506. & 'reg' 'add' 'HKLM\zSYSTEM\ControlSet001\Control\BitLocker' '/v' 'PreventDeviceEncryption' '/t' 'REG_DWORD' '/d' '1' '/f' | Out-Null
  507. Write-Host "优化完成!"
  508. Write-Host "卸载注册表..."
  509. reg unload HKLM\zNTUSER
  510. reg unload HKLM\zDEFAULT
  511. reg unload HKLM\zSOFTWARE
  512. reg unload HKLM\zSYSTEM >null
  513. Start-Sleep -Seconds 10
  514. & 'dism' '/English' '/unmount-image' "/mountdir:$scratchDir" '/commit'
  515. & takeown "/F" $bootWimPath
  516. & icacls $bootWimPath "/grant" "$($adminGroup.Value):(F)"
  517. Remove-Item -Path $bootWimPath -Force
  518. & 'dism' '/English' '/Export-Image' "/SourceImageFile:$newBootWimPath" '/SourceIndex:1' "/DestinationImageFile:$finalBootWimPath" '/compress:max'
  519. Remove-Item -Path $newBootWimPath -Force
  520. Rename-Item -Path $finalBootWimPath -NewName "boot.wim"

  521. Clear-Host
  522. Write-Host ""将最终镜像导出为高压缩 ESD 格式...""
  523. & dism /Export-Image /SourceImageFile:"$mainOSdrive\nano11\sources\install.wim" /SourceIndex:1 /DestinationImageFile:"$mainOSdrive\nano11\sources\install.esd" /Compress:recovery
  524. Remove-Item "$mainOSdrive\nano11\sources\install.wim"  2>&1

  525. Write-Host "执行安装文件夹根目录的最终清理..."
  526. $isoRoot = "$mainOSDrive\nano11"
  527. $keepList = @("boot", "efi", "sources", "bootmgr", "bootmgr.efi", "setup.exe", "autounattend.xml")
  528. Get-ChildItem -Path $isoRoot | Where-Object { $_.Name -notin $keepList } | ForEach-Object {
  529.     Write-Host "从 ISO 根目录移除非必要文件/文件夹: $($_.Name)"
  530.     Remove-Item -Path $_.FullName -Recurse -Force
  531. }

  532. Write-Host "创建可启动 ISO 镜像..."
  533. $OSCDIMG = "$PSScriptRoot\oscdimg.exe"
  534. if (-not (Test-Path $OSCDIMG)) { $url = "https://msdl.microsoft.com/download/symbols/oscdimg.exe/3D44737265000/oscdimg.exe"; Invoke-WebRequest -Uri $url -OutFile $OSCDIMG }
  535. & "$OSCDIMG" '-m' '-o' '-u2' '-udfver102' "-bootdata:2#p0,e,b$mainOSdrive\nano11\boot\etfsboot.com#pEF,e,b$mainOSdrive\nano11\efi\microsoft\boot\efisys.bin" "$mainOSdrive\nano11" "$PSScriptRoot\nano11.iso"

  536. Write-Host "创建完成! 您的 ISO 文件名为 nano11.iso"
  537. Read-Host "按 Enter 键执行清理并退出。"
  538. & 'dism' '/English' '/unmount-image' "/mountdir:$scratchDir" '/discard'
  539. Remove-Item -Path "$mainOSdrive\nano11" -Recurse -Force
  540. Remove-Item -Path "$mainOSdrive\scratchdir" -Recurse -Force
  541. Stop-Transcript
  542. exit
  543. }
  544. else {
  545.     Write-Host "You chose not to continue. The script will now exit."
  546.     exit
  547. }
复制代码


评分

参与人数 2无忧币 +10 收起 理由
某些人 + 5 赞一个!
yyz2191958 + 5

查看全部评分

2#
发表于 昨天 17:32 | 只看该作者
真快哈,
回复

使用道具 举报

3#
发表于 昨天 17:35 | 只看该作者
谢谢楼主分享哈
回复

使用道具 举报

4#
发表于 昨天 17:44 | 只看该作者
支持发布
回复

使用道具 举报

5#
发表于 昨天 17:59 | 只看该作者
支持原创
回复

使用道具 举报

6#
发表于 昨天 18:05 | 只看该作者
谢谢分享
回复

使用道具 举报

7#
发表于 昨天 18:06 | 只看该作者
支持一下
回复

使用道具 举报

8#
发表于 昨天 18:48 | 只看该作者

谢谢楼主分享哈
回复

使用道具 举报

9#
发表于 昨天 19:10 | 只看该作者
这个脚本怎么用

点评

保存成.PS1文件运行  详情 回复 发表于 昨天 19:12
回复

使用道具 举报

10#
 楼主| 发表于 昨天 19:12 | 只看该作者
aeneid 发表于 2025-9-12 19:10
这个脚本怎么用

保存成.PS1文件运行
回复

使用道具 举报

11#
发表于 昨天 19:22 | 只看该作者
谢谢分享
回复

使用道具 举报

12#
发表于 昨天 19:32 | 只看该作者
谢谢分享!
回复

使用道具 举报

13#
发表于 昨天 19:53 | 只看该作者
感谢分享
回复

使用道具 举报

14#
发表于 昨天 21:30 | 只看该作者
谢谢啊  速度好快啊
回复

使用道具 举报

15#
发表于 昨天 21:54 | 只看该作者

感谢楼主分享
回复

使用道具 举报

16#
发表于 昨天 22:36 | 只看该作者
小白不建议使用,借鉴下其内容还行。
回复

使用道具 举报

17#
发表于 昨天 23:14 | 只看该作者
感谢楼主的分享
回复

使用道具 举报

18#
发表于 28 分钟前 | 只看该作者
感谢分享!
回复

使用道具 举报

19#
发表于 26 分钟前 | 只看该作者
谢谢分享,辛苦啦!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2025-9-13 00:37

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表