|
本帖最后由 倒垃圾的歌者 于 2024-9-7 15:09 编辑
这些封装工具实际上就有这功能
当然你也可以用批处理执行
- @echo off
- setlocal enabledelayedexpansion
- set "letters=ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- set "numbers=0123456789"
- set "random_name=WIN-"
- REM 生成随机的大写字母
- FOR /L %%i IN (1,1,8) DO (
- set /a index=!random! %% 26
- call set "random_letter=%%letters:~!index!,1%%"
- set "random_name=!random_name!!random_letter!"
- )
- REM 生成随机的数字字符
- set /a count=0
- FOR /L %%i IN (1,1,5) DO (
- set /a index=!random! %% 10
- call set "random_number=%%numbers:~!index!,1%%"
- set "random_name=!random_name!!random_number!"
- set /a count+=1
- )
- REM 如果生成的随机数字不足2个,补充生成
- if %count% LSS 2 (
- FOR /L %%i IN (%count%,1,1) DO (
- set /a index=!random! %% 10
- call set "random_number=%%numbers:~!index!,1%%"
- set "random_name=!random_name!!random_number!"
- set /a count+=1
- )
- )
- echo 新的设备名称: %random_name%
- wmic computersystem where name="%computername%" call rename name="%random_name%"
- rem 如果重启电脑移除下面这个rem
- rem shutdown -r -t 5 -f
- del %0
复制代码
|
|