|
本帖最后由 hlowld 于 2025-6-30 09:45 编辑
如果楼主想要的是 “跳过OOBE,并自定义创建本地账户”,恰好前段时间也想过这个问题,分享一下我的方案
1、unattend.xml中跳过OOBE- <?xml version="1.0" encoding="utf-8"?>
- <unattend xmlns="urn:schemas-microsoft-com:unattend">
- <settings pass="oobeSystem">
- <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
- <InputLocale>zh-CN</InputLocale>
- <SystemLocale>zh-CN</SystemLocale>
- <UILanguage>zh-CN</UILanguage>
- <UserLocale>zh-CN</UserLocale>
- </component>
- <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
- <OOBE>
- <ProtectYourPC>3</ProtectYourPC>
- <HideEULAPage>true</HideEULAPage>
- <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
- <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
- <HideOnlineAccountScreens>true</HideOnlineAccountScreens>
- <HideLocalAccountScreen>true</HideLocalAccountScreen>
- <SkipMachineOOBE>true</SkipMachineOOBE>
- <SkipUserOOBE>true</SkipUserOOBE>
- </OOBE>
- </component>
- </settings>
- </unattend>
复制代码
2、编写创建本地账户的批处理localaccount.cmd,倒计时10秒,若检测到按键,则交互界面创建账户后退出,否则创建admin空密码账户后退出
- @echo off
- setlocal enabledelayedexpansion
- title 创建用户,请勿关闭本窗口
- for /l %%i in (10, -1, 1) do (
- <nul set /p="将于 %%i 秒后自动创建 admin 空密码用户并退出,按任意键创建自定义用户 ..."
- powershell.exe -noprofile -command "if ([console]::KeyAvailable) { $host.UI.RawUI.FlushInputBuffer(); exit 1 } else { exit 0 }" >nul 2>nul
- if errorlevel 1 (cls & goto :want_uname)
- ping 127.0.0.1 -n 1 -w 1000 >nul
- cls
- )
- cls
- net user admin /add >nul 2>nul && (
- net localgroup administrators admin /add >nul 2>nul && (echo 自动创建 admin 空密码用户成功,即将退出 & timeout /t 2 >nul & exit) || (net user admin /delete >nul 2>nul)
- )
- echo 自动创建 admin 空密码用户失败,强制创建自定义用户
- :want_uname
- echo.
- set "uname="
- set /p uname=请键入用户名:
- if "%uname%" == "" goto want_uname
- :want_upass
- set "upass="
- for /f "delims=" %%P in ('powershell.exe -NoProfile -Command "$pwd = Read-Host ''请键入用户的密码'' -AsSecureString; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd))"') do set "upass=%%P"
- set "upass2="
- for /f "delims=" %%P in ('powershell.exe -NoProfile -Command "$pwd = Read-Host ''请再键入一次密码以便确认'' -AsSecureString; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd))"') do set "upass2=%%P"
- if "%upass%" neq "%upass2%" (echo 密码不匹配。 & goto want_upass)
- if "%upass%" equ "" (
- net user %uname% /add >nul 2>nul && (
- net localgroup administrators %uname% /add >nul 2>nul && (echo 创建 %uname% 用户成功,即将退出 & timeout /t 2 >nul & exit) || (echo 加入管理员群组失败 & net user %uname% /delete >nul 2>nul & goto want_uname)
- ) || (echo 创建 %uname% 用户失败 & goto want_uname)
- ) else (
- net user %uname% %upass% /add >nul 2>nul && (
- net localgroup administrators %uname% /add >nul 2>nul && (echo 创建 %uname% 用户成功,即将退出 & timeout /t 2 >nul & exit) || (echo 加入管理员群组失败 & net user %uname% /delete >nul 2>nul & goto want_uname)
- ) || (echo 创建 %uname% 用户失败 & goto want_uname)
- )
- exit
复制代码 3、SetupComplete.cmd中调用localaccount.cmd
- start /wait "localaccount" "%~dp0localaccount.cmd"
复制代码 4、挂载镜像Users\Default\ntuser.dat修改,禁止同意个人数据跨境传输界面
- reg load HKEY_USERS\uuu z:\Users\Default\ntuser.dat >nul 2>nul
- reg.exe add "HKEY_USERS\uuu\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudExperienceHost\Intent\PersonalDataExport" /v "PDEShown" /t REG_DWORD /d "2" /f >nul 2>nul
- reg unload HKEY_USERS\uuu >nul 2>nul
复制代码 5、同理,可以编写修改计算机名的批处理computername.cmd并在SetupComplete.cmd中调用,倒计时10秒,若检测到按键,则交互界面修改计算机名后退出,否则修改为随机名称后退出。注意:修改计算机名重启后才能生效
- @echo off
- setlocal enabledelayedexpansion
- title 设置计算机名,请勿关闭本窗口
- set "cname=WIN-%RANDOM%"
- for /l %%i in (10, -1, 1) do (
- <nul set /p="将于 %%i 秒后自动设置计算机名为 %cname% 并退出,按任意键手工设置 ..."
- powershell.exe -noprofile -command "if ([console]::KeyAvailable) { $host.UI.RawUI.FlushInputBuffer(); exit 1 } else { exit 0 }" >nul 2>nul
- if errorlevel 1 (cls & goto :want_name)
- ping 127.0.0.1 -n 1 -w 1000 >nul
- cls
- )
- cls
- goto set_name
- :want_name
- echo.
- set "cname="
- set /p cname=请键入计算机名(字母、连字符和数字的组合):
- if "%cname%" == "" goto want_name
- :set_name
- powershell.exe -noprofile -command "Rename-Computer -NewName '%cname%'" >nul 2>nul
- if errorlevel 0 (echo 设置计算机名为 %cname% 成功,即将退出 & timeout /t 2 >nul & exit)
- echo 设置计算机名为 %cname% 失败 & goto want_name
- exit
复制代码
当然,这些操作,都由一个批处理来自动实现,无需手动。
|
|