A-A+

Windows 批处理自动根据当前日期时间修改计算机名

2021年09月17日 拾到贝壳, 点滴记录 Windows 批处理自动根据当前日期时间修改计算机名已关闭评论 阅读 2,897 次

Windows 批处理自动根据当前日期时间修改计算机名

 

@echo off  
echo     修改计算机器名...
set pcname=Oo-%date:~2,2%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
echo Windows Registry Editor Version 5.00>ComputerName.reg 
echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam]>>ComputerName.reg 
echo @="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName]>>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>c:\TempInfo.reg>>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]>>ComputerName.reg 
echo "NV Hostname"="%pcname%">>ComputerName.reg 
echo "Hostname"="%pcname%">>ComputerName.reg 
echo [HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\ShellNoRoam]>>ComputerName.reg 
echo @="%pcname%">>ComputerName.reg 
regedit /s ComputerName.reg 
del /q ComputerName.reg 
echo     修改计算机器名称完成...

或者随机生成 15 位字母数字组合作为计算机名:

随机数生成代码来自:此处

@echo off & setlocal enabledelayedexpansion 
echo     修改计算机器名...

set str=ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890

for /l %%a in (1 1 15) do (
	set /a n=!random!%%36
	call set a=%%str:~!n!,1%%!a!
)
set pcname=%a%
echo Windows Registry Editor Version 5.00>ComputerName.reg 
echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam]>>ComputerName.reg 
echo @="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName]>>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>c:\TempInfo.reg>>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName]>>ComputerName.reg 
echo "ComputerName"="%pcname%">>ComputerName.reg 
echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]>>ComputerName.reg 
echo "NV Hostname"="%pcname%">>ComputerName.reg 
echo "Hostname"="%pcname%">>ComputerName.reg 
echo [HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\ShellNoRoam]>>ComputerName.reg 
echo @="%pcname%">>ComputerName.reg 
regedit /s ComputerName.reg 
del /q ComputerName.reg 
echo     修改计算机器名称完成...

代码修改自:http://www.5x54.com/article/html/200709/27114128.html

标签:

评论已关闭!

Copyright © 海边拾贝 保留所有权利.   Theme  Ality 鲁ICP备17020531号-1
网站已运行: | 耗时 0.474 秒 | 查询 53 次 | 内存 31.24 MB

用户登录