|
支持静默参数
1)PCName.bat -time
按当前执行脚本时间设置计算机名:PC-202311081358
2)PCName.bat -rand
按随机字符串设置计算机名:PC-EDLH70GN80R7
3)PCName.bat WinPE
按自定义字符串设置计算机名
- @echo off
- if /i "%UserName%" == "SYSTEM" (Goto GotAdmin) else (reg query "HKLM\SYSTEM\ControlSet001\Control\MiniNT" 1>nul 2>nul&&Goto GotAdmin)
- :BatchGotAdmin
- Set _Args=%*
- if `%1` neq `` Set "_Args=%_Args:"=""%"
- if exist %WinDir%\System32\fltMC.exe fltMC 1>nul 2>nul||mshta VBScript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c """"%~f0"" %_Args%""",,"runas",1)(Window.Close) 2>nul&&Exit /b
- :GotAdmin
- Pushd "%CD%"&cd /d "%~dp0"
- Set PN=PC-
- for /f "tokens=2*" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" 2^>nul') do Set "OName=%%j"
- >"%TEMP%/DateCalculate.vbs" echo dt=date()
- >>"%TEMP%/DateCalculate.vbs" echo tm=time()
- >>"%TEMP%/DateCalculate.vbs" echo s=right(year(dt),4) ^& right("0" ^& month(dt),2) ^& right("0" ^& day(dt),2) ^& right("0" ^& Hour(tm),2) ^& right("0" ^& minute(tm),2)
- >>"%TEMP%/DateCalculate.vbs" echo wscript.echo s
- cscript 1>nul 2>nul&&for /f %%a in ('cscript /nologo "%TEMP%/DateCalculate.vbs"') do Set "TName=%PN%%%a"
- setlocal enabledelayedexpansion
- Set var=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
- Set id=&for /l %%i in (1,1,12) do (Set /a n=!random!%%36&for %%j in (!n!) do Set id=!id!!var:~%%j,1!)
- endlocal&Set RName=%PN%%id%
- Set NName=%1
- if defined NName Goto ModName
- :ShowName
- Title 计算机名&Color 2f
- MODE 1>nul 2>nul&&MODE con: Cols=45 Lines=12
- echo ★设置计算机名★
- echo ----------------
- if defined OName Call :EchoX "xx::◎保留原名称(" "70::直接 回车" "xx.:) %OName%"
- if defined TName Call :EchoX "xx::◎按时间命名(" "70::输入-time" "xx.:) %TName%"
- if defined RName Call :EchoX "xx::◎随机串命名(" "70::输入-rand" "xx.:) %RName%"
- Call :EchoX "xx::◎更换新名称(" "70::输入新名称后回车" "xx.:)↓"
- echo --------------------------------------------
- Set /p NName=
- if not defined NName Exit /b
- :ModName
- if /i "%NName%" == "-time" Set "NName=%TName%"
- if /i "%NName%" == "-rand" Set "NName=%RName%"
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /f /v "ComputerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /f /v "ComputerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /f /v "Hostname" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /f /v "NV Hostname" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\EventLog\State" /f /v "LastComputerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName" /f /v "ComputerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Control\ComputerName\ComputerName" /f /v "ComputerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /f /v "Hostname" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /f /v "NV Hostname" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Services\EventLog\State" /f /v "LastComputerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" 1>nul 2>nul&&(
- reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" /f /v "uNCName" /t REG_SZ /d "\\%NName%\Fax" 1>nul 2>nul
- reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" /f /v "serverName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" /f /v "shortServerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- )
- reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" 1>nul 2>nul&&(
- reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" /f /v "uNCName" /t REG_SZ /d "\\%NName%\Fax" 1>nul 2>nul
- reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" /f /v "serverName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Print\Printers\Fax\DsSpooler" /f /v "shortServerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- )
- reg query "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Fax\DsSpooler" 1>nul 2>nul&&(
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Fax\DsSpooler" /f /v "uNCName" /t REG_SZ /d "\\%NName%\Fax" 1>nul 2>nul
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Fax\DsSpooler" /f /v "serverName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers\Fax\DsSpooler" /f /v "shortServerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- )
- reg query "HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Fax\DsSpooler" 1>nul 2>nul&&(
- reg add "HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Fax\DsSpooler" /f /v "uNCName" /t REG_SZ /d "\\%NName%\Fax" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Fax\DsSpooler" /f /v "serverName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- reg add "HKLM\SYSTEM\ControlSet001\Control\Print\Printers\Fax\DsSpooler" /f /v "shortServerName" /t REG_SZ /d "%NName%" 1>nul 2>nul
- )
- Exit /b
- :EchoX :: 显示彩色文字 (不支持半角字符 \ / : * ? " < >|. % ! ~)。
- setlocal enabledelayedexpansion
- Set echox=EchoX.exe&&!echox! 1>nul 2>nul||(Set echox=&mkdir "%TEMP%\EchoX" 2>nul)
- for %%a in (%*) do (
- Set "param=%%a"&Set "param=!param:"=!"
- Set "color=!param:~0,2!"&(if not exist %WinDir%\System32\findstr.exe if not defined echox Set "color=xx")
- Set n=0&(if "!param:~2,2!" == "::" Set n=1)&(if "!param:~2,2!" == ".:" Set n=2)
- if !n! gtr 0 (
- if /i "!color!" == "xx" (Set /p="_!param:~4!"<nul) else (Set param=%%~nxa&if defined echox (!echox! -c !color! -n "!param:~4!") else (Pushd "%TEMP%\EchoX" 2>nul&>"!param:~4!",Set /p= <nul&findstr /a:!color! .* "!param:~4!*"&del "!param:~4!"&Popd))
- if !n! == 2 echo.
- ) else if defined param Set /p="_!param!"<nul
- )
- endlocal
- Goto :eof
复制代码
|
评分
-
查看全部评分
|