window批处理修改计算机名,工作组的批处理
分类:美高梅-操作

一、需要重启

复制代码 代码如下:

本人负责的部门有上百台机器,重装完后需要恢复原有配置,我曾使用过很多方法:
1:手工更改,这条就不要说了
2:使用netsh dump +文件和 netsh -f +文件来更改,但是整个盘都格式化就没用.
3:使用专用的更改ip地址的小程序,但还是需要手工来指定IP

复制代码 代码如下:

@echo off
set /p pcnanme=请输入计算机的名字:
reg add HKEY_LOCAL_MACHINESYSTEMControlSet001ControlComputerNameComputerName /v ComputerName /t REG_SZ /d %pcnanme% /f
eixt

@echo off
echo 骏龙包装计算机名称、计算机描述、工作组修改批处理程序
Echo
pause
cls
:set/p id=请输入本机网段号:
:set/p ip=请输入本机IP地址:
:netsh interface ip set address name="本地连接" source=static addr=192.168.%id%.%ip% mask=255.255.255.0
set /p name=请输您的主机出厂S/N编号:
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetControlComputerNameActiveComputerName" /v ComputerName /t reg_sz /d %name% /f
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters" /v "NV Hostname" /t reg_sz /d %name% /f
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters" /v Hostname /t reg_sz /d %name% /f
SET work=骏龙
wmic computersystem where Name="%NAME%" call JoinDomainOrWorkgroup Name="%work%"
set /p describe=请输入您的计算机描述(公司规定必须是使用者姓名):
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServiceslanmanserverParameters" /v srvcomment /t reg_sz /d %describe% /f

最后,我想到如下办法:
1:首先实现:netsh interface ip 来更改IP
2:使用wmic computersystem 修改工作组
3:使用reg add 来更改机器名
4:因为修改机器名后要重启才生效,于是使用:reboot.inf 来重启
5:后来增加了新机器名和ip的配置,使用机器的序列号(联想机:wmic bios get SerialNumber)来做机器名,ip地址最后1位使用随机
因为可以通过 wmic来读取序列号,那么我们可以用来登记本机的网络配置时,就方便多了.
6:最后将自己整理的IP地址等对应表放到了bat中,避免bat调用其他文件.
7:实现上面功能后,我就可以将该bat文件封装到gho文件里面,恢复重启完后就可以自动设置,我不要做其他操作,用户就可以使用.如果有必要,你可以加上执行完后自动删除本身.

@echo off
echo ----------------------------------
美高梅网站是多少,echo ----正在备份注册表 请稍后....----
echo ----------------------------------
  reg export "HKEY_LOCAL_MACHINE" C:/reg_backup.reg
echo ----------------------
echo ----注册表备份完成----
echo ----------------------
  ping 127.0.0.1 -n 3 >nul
echo -----------------------------------
echo ----安全配置正在改写 请稍候...----
echo -----------------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------
echo ----正在禁用空连接----
echo ----------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsa /v restrictanonymous /t reg_dword /d 1 /f
echo --------------------------
echo ----禁用空连接设置完毕----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------
echo ----正在删除默认共享----
echo ------------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServiceslanmanserverparameters /v AutoShareServer /t reg_dword /d 0 /f
echo ----------------------------
echo ----删除默认共享设置完毕----
echo ----------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------
echo ----正在修改TTL值请稍后...----
echo ------------------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v DefaultTTL /t reg_dword /d 53 /f
echo -------------------
echo ----TTL修改完毕----
echo -------------------
  @ping 127.0.0.1 -n 3 >nul
echo -----------------------
echo ----防止syn洪水攻击----
echo -----------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v SynAttackProtect /t reg_dword /d 2 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v EnablePMTUDiscovery /t reg_dword /d 0 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v NoNameReleaseOnDemand /t reg_dword /d 1 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v EnableDeadGWDetect /t reg_dword /d 0 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v KeepAliveTime /t reg_dword /d 300000 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v PerformRouterDiscovery /t reg_dword /d 0 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v EnableICMPRedirects /t reg_dword /d 0 /f
美高梅4858官方网站,echo -------------------------------
echo ----防止syn洪水攻击设置完毕----
echo -------------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------
echo ------------------------------
echo ---- 系统服务修改 ----
echo ------------------------------
echo ------------------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------
echo ----修改3389端口----
echo --------------------
  reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWds dpwdTdstcp" /v PortNumber /t reg_dword /d 44454 /f
  reg add "HKEY_LOCAL_MACHINESYSTEMCurrentContro1SetControlTenninal ServerWinStationsRDPTcp" /v PortNumber /t reg_dword /d 44454 /f
echo --------------------
echo ----修改PORT完毕----
echo --------------------
  @ping 127.0.0.1 -n 3 >nul
echo -------------------------------------
echo ----正在开启系统防火墙 请稍后....----
echo -------------------------------------
  sc config sharedaccess start= auto & net start sharedaccess
echo ------------------------
echo ----系统防火墙已开启----
echo ------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------
echo ----正在关闭共享打印服务----
echo ----------------------------
  @sc config Spooler start= disabled
  sc config LanmanServer start= disabled
  sc config LmHosts start= disabled
echo --------------------------
echo ----已关闭共享打印服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------
echo ----正在关闭远程协助服务----
echo ----------------------------
  @sc config RDSessMgr start= disabled
echo --------------------------
echo ----已关闭远程协助服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------
echo ----正在关闭远程注册表服务----
echo ------------------------------
  @sc config RemoteRegistry start= disabled
echo ----------------------------
echo ----已关闭远程注册表服务----
echo ----------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------
echo ----关闭自动硬件播放通知----
echo ----------------------------
  sc config ShellHWDetection start= disabled
echo -----------------------
echo ----自动播放通知关闭---
echo -----------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------------------
echo ----正在关闭替换凭据下的启动进程服务----
echo ----------------------------------------
  sc config seclogon start= disabled
echo --------------------------
echo ----已关闭启动进程服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------------
echo ----IEEE 802.11 适配器的自动配置----
echo ------------------------------------
  sc config WZCSVC start= disabled
echo ------------------
echo ----已关闭IEEE----
echo ------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------------
echo ----客户端跟踪服务关闭----
echo --------------------------
  sc config TrkSvr start= disabled
  sc config MSDTC start= disabled
echo ----------------------------
echo ----已关闭客户端跟踪服务----
echo ----------------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------
echo ----帮助中心关闭----
echo --------------------
  sc config helpsvc start= disabled
echo --------------------------
echo ----已关闭帮助中心服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------------------
echo --------------------------------
echo ---- 系统权限加固 ----
echo --------------------------------
echo --------------------------------
echo -------------------------------------------------------
echo ----C盘(系统盘) (administrators,system完全控制权限)----
echo -------------------------------------------------------
  cacls C: /t /c /g administrators:F system:F
echo -------------------------------------------
echo ----Common Files (everyone用户只读权限)----
echo -------------------------------------------
  Cacls "C:Program FilesCommon Files" /t /e /c /g everyone:R
echo -------------------------------------------------------------
echo ----IIS Temporary Compressed Files (everyone用户更改权限)----
echo -------------------------------------------------------------
  Cacls "C:WINDOWSIIS Temporary Compressed Files" /t /e /c /g everyone:C
echo --------------------------------------------
echo ----Microsoft.Net (everyone用户只读权限)----
echo --------------------------------------------
  Cacls C:WINDOWSMicrosoft.Net /t /e /c /g everyone:R
echo ------------------------------------------------------
echo ----Temporary ASP.NET Files (everyone用户更改权限)----
echo ------------------------------------------------------
  Cacls "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files" /t /e /c /g everyone:C
echo ------------------------------------------------------
echo ----Temporary ASP.NET Files (everyone用户更改权限)----
echo ------------------------------------------------------
  Cacls "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files" /t /e /c /g everyone:C
echo -------------------------------------------
echo ----Registration (everyone用户读取权限)----
echo -------------------------------------------
  Cacls C:WINDOWSRegistration /t /e /c /g everyone:R
echo -----------------------------------
echo ----Temp (everyone用户更改权限)----
echo -----------------------------------
  Cacls C:WINDOWSTemp /t /e /c /g everyone:C
echo -------------------

需要重启电脑才能生效

net config server /SRVCOMMENT:"%describe%"
pause

整个代码如下:(欢迎大家继续优化和整理)

 @echo off
echo ----------------------------------
echo ----正在备份注册表 请稍后....----
echo ----------------------------------
  reg export "HKEY_LOCAL_MACHINE" C:/reg_backup.reg
echo ----------------------
echo ----注册表备份完成----
echo ----------------------
  ping 127.0.0.1 -n 3 >nul
echo -----------------------------------
echo ----安全配置正在改写 请稍候...----
echo -----------------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------
echo ----正在禁用空连接----
echo ----------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsa /v restrictanonymous /t reg_dword /d 1 /f
echo --------------------------
echo ----禁用空连接设置完毕----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------
echo ----正在删除默认共享----
echo ------------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServiceslanmanserverparameters /v AutoShareServer /t reg_dword /d 0 /f
echo ----------------------------
echo ----删除默认共享设置完毕----
echo ----------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------
echo ----正在修改TTL值请稍后...----
echo ------------------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v DefaultTTL /t reg_dword /d 53 /f
echo -------------------
echo ----TTL修改完毕----
echo -------------------
  @ping 127.0.0.1 -n 3 >nul
echo -----------------------
echo ----防止syn洪水攻击----
echo -----------------------
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v SynAttackProtect /t reg_dword /d 2 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v EnablePMTUDiscovery /t reg_dword /d 0 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v NoNameReleaseOnDemand /t reg_dword /d 1 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v EnableDeadGWDetect /t reg_dword /d 0 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v KeepAliveTime /t reg_dword /d 300000 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v PerformRouterDiscovery /t reg_dword /d 0 /f
  reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters /v EnableICMPRedirects /t reg_dword /d 0 /f
echo -------------------------------
echo ----防止syn洪水攻击设置完毕----
echo -------------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------
echo ------------------------------
echo ---- 系统服务修改 ----
echo ------------------------------
echo ------------------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------
echo ----修改3389端口----
echo --------------------
  reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWds dpwdTdstcp" /v PortNumber /t reg_dword /d 44454 /f
  reg add "HKEY_LOCAL_MACHINESYSTEMCurrentContro1SetControlTenninal ServerWinStationsRDPTcp" /v PortNumber /t reg_dword /d 44454 /f
echo --------------------
echo ----修改PORT完毕----
echo --------------------
  @ping 127.0.0.1 -n 3 >nul
echo -------------------------------------
echo ----正在开启系统防火墙 请稍后....----
echo -------------------------------------
  sc config sharedaccess start= auto & net start sharedaccess
echo ------------------------
echo ----系统防火墙已开启----
echo ------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------
echo ----正在关闭共享打印服务----
echo ----------------------------
  @sc config Spooler start= disabled
  sc config LanmanServer start= disabled
  sc config LmHosts start= disabled
echo --------------------------
echo ----已关闭共享打印服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------
echo ----正在关闭远程协助服务----
echo ----------------------------
  @sc config RDSessMgr start= disabled
echo --------------------------
echo ----已关闭远程协助服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------
echo ----正在关闭远程注册表服务----
echo ------------------------------
  @sc config RemoteRegistry start= disabled
echo ----------------------------
echo ----已关闭远程注册表服务----
echo ----------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------
echo ----关闭自动硬件播放通知----
echo ----------------------------
  sc config ShellHWDetection start= disabled
echo -----------------------
echo ----自动播放通知关闭---
echo -----------------------
  @ping 127.0.0.1 -n 3 >nul
echo ----------------------------------------
echo ----正在关闭替换凭据下的启动进程服务----
echo ----------------------------------------
  sc config seclogon start= disabled
echo --------------------------
echo ----已关闭启动进程服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo ------------------------------------
echo ----IEEE 802.11 适配器的自动配置----
echo ------------------------------------
  sc config WZCSVC start= disabled
echo ------------------
echo ----已关闭IEEE----
echo ------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------------
echo ----客户端跟踪服务关闭----
echo --------------------------
  sc config TrkSvr start= disabled
  sc config MSDTC start= disabled
echo ----------------------------
echo ----已关闭客户端跟踪服务----
echo ----------------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------
echo ----帮助中心关闭----
echo --------------------
  sc config helpsvc start= disabled
echo --------------------------
echo ----已关闭帮助中心服务----
echo --------------------------
  @ping 127.0.0.1 -n 3 >nul
echo --------------------------------
echo --------------------------------
echo ---- 系统权限加固 ----
echo --------------------------------
echo --------------------------------
echo -------------------------------------------------------
echo ----C盘(系统盘) (administrators,system完全控制权限)----
echo -------------------------------------------------------
  cacls C: /t /c /g administrators:F system:F
echo -------------------------------------------
echo ----Common Files (everyone用户只读权限)----
echo -------------------------------------------
  Cacls "C:Program FilesCommon Files" /t /e /c /g everyone:R
echo -------------------------------------------------------------
echo ----IIS Temporary Compressed Files (everyone用户更改权限)----
echo -------------------------------------------------------------
  Cacls "C:WINDOWSIIS Temporary Compressed Files" /t /e /c /g everyone:C
echo --------------------------------------------
echo ----Microsoft.Net (everyone用户只读权限)----
echo --------------------------------------------
  Cacls C:WINDOWSMicrosoft.Net /t /e /c /g everyone:R
echo ------------------------------------------------------
echo ----Temporary ASP.NET Files (everyone用户更改权限)----
echo ------------------------------------------------------
  Cacls "C:WINDOWSMicrosoft.NETFrameworkv1.1.4322Temporary ASP.NET Files" /t /e /c /g everyone:C
echo ------------------------------------------------------
echo ----Temporary ASP.NET Files (everyone用户更改权限)----
echo ------------------------------------------------------
  Cacls "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Files" /t /e /c /g everyone:C
echo -------------------------------------------
echo ----Registration (everyone用户读取权限)----
echo -------------------------------------------
  Cacls C:WINDOWSRegistration /t /e /c /g everyone:R
echo -----------------------------------
echo ----Temp (everyone用户更改权限)----
echo -----------------------------------
  Cacls C:WINDOWSTemp /t /e /c /g everyone:C
echo -------------------
echo ----assembly (everyone用户读取权限)----
echo ---------------------------------------
  Cacls C:WINDOWSassembly /t /e /c /g everyone:R
echo -------------------------------------
echo ----WinSxS (everyone用户读取权限)----
echo -------------------------------------
  Cacls C:WINDOWSWinSxS /t /e /c /g everyone:R
echo ------------------------------------
echo ----Fonts (everyone用户读取权限)----
echo ------------------------------------
  Cacls C:WINDOWSFonts /t /e /c /g everyone:R
echo ---------------------------------------
echo ----System32 (everyone用户读取权限)----
echo ---------------------------------------
  Cacls C:WINDOWSSystem32 /t /e /c /g everyone:R
echo ------------------------------------------
echo ----msdtc (networkservice用户更改权限)----
echo ------------------------------------------
  Cacls C:windowssystem32msdtc /t /e /c /g networkservice:C
echo -----------------------------------------------------
echo ----ASP Compiled Templates (everyone用户更改权限)----
echo -----------------------------------------------------
  Cacls "C:WINDOWSsystem32inetsrvASP Compiled Templates" /t /e /c /g everyone:C
echo ------------------------------------
echo ----*.exe (去除everyone用户权限)----
echo ------------------------------------
  Cacls C:WINDOWSSystem32*.exe /e /c /r everyone
echo ------------------------------------
echo ----cmd.exe (去除system用户权限)----
echo ------------------------------------
  Cacls C:WINDOWSSystem32cmd.exe /e /c /r system
echo ------------------------------------
echo ----net.exe (去除system用户权限)----
echo ------------------------------------
  Cacls C:WINDOWSSystem32 et.exe /e /c /r system
echo -------------------------------------
echo ----net1.exe (去除system用户权限)----
echo -------------------------------------
  Cacls C:WINDOWSSystem32 et1.exe /e /c /r system
echo ----------------------------------------
echo ----msdtc.exe (everyone用户读取权限)----
echo ----------------------------------------
  Cacls C:WINDOWSSystem32msdtc.exe /e /c /g everyone:R
echo ------------------------------------------
echo ----dllhost.exe (everyone用户读取权限)----
echo ------------------------------------------
  Cacls C:WINDOWSSystem32dllhost.exe /e /c /g everyone:R
echo ------------------------------------------
echo ----svchost.exe (everyone用户读取权限)----
echo ------------------------------------------
  Cacls C:WINDOWSSystem32svchost.exe /e /c /g everyone:R
echo --------------------
echo --------------------
echo ----系统加固完毕----
echo --------------------
echo --------------------
  @ping 127.0.0.1 -n 3 >nul
echo -----------------------------
echo ----安全设置完毕 欢迎使用----
echo -----------------------------
echo ------------------
echo ----重启服务器----
echo ------------------
  @ping 127.0.0.1
  shutdown -r
  @pause

 

用批处理修改计算机名和工作组,不用重启!

复制代码 代码如下:

将上面的代码保存为1.cmd或1.bat,双击运行下即可。

二、不需要重启

如果你喜欢用Ghost镜像的系统,那么每次重装完成之后的计算机名都是一串长长的随机字符,非常不方便和不美观。
一般来说,你在系统属性那里修改计算机名或者工作组,总是要进行重新启动,非常麻烦。甚至在最新的Vista操作系统里面也是这样。
其实计算机名是保存在注册表里面的,我们可以通过直接修改注册表,达到修改的目的。

@echo off & code by m13632750052
for /f "tokens=12 delims= " %%i in ('ipconfig/all^|find "Physical Address"') do set localmac=%%i
echo 通过MAC地址%localmac%查找对应的机器名
for /f "skip=90 tokens=1,2,3,4 delims= " %%i in (%~f0) do (
if [%%k]==[%localmac%] set Name=%%i
if [%%k]==[%localmac%] set IP=%%j
if [%%k]==[%localmac%] set MAC=%%k
if [%%k]==[%localmac%] set Workgroup=%%l
set mask=255.255.0.0
set gway=168.30.1.233
set dns=168.1.4.147
set dns2=168.1.6.243
)
echo 显示查找结果 code by cn-dos breakme
if defined Name (echo %Name% %IP% %mac% %Workgroup%) else (goto newset)
:Enterset
for /l %%i in (3,-1,0) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后修改机器名……

@echo off
set /p name=输入新的计算机名称
wmic computersystem where "PrimaryOwnerName='%username%'" call rename %NAME%&exit
利用wmic改名不用重启

复制代码 代码如下:

reg add "HKEY_CURRENT_USERSoftwareMicrosoftWindowsShellNoRoam" /v @ /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetControlComputerNameComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetControlComputerNameActiveComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetServicesEventlog" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetControlComputerNameComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetServicesTcpipParameters" /v "NV Hostname" /t REG_SZ /d "%Name%" /f
reg add "HKLMSYSTEMCurrentControlSetServicesTcpipParameters" /v "Hostname" /t REG_SZ /d "%Name%" /f

 

HKEY_LOCAL_MACHINESystemCurrentControlSetControlComputerNameActiveComputerName
HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters

echo 刷新注册表
if exist c:winnt (secedit /refreshpolicy machine_policy /enforce) else (gpupdate /force)

 

工作组的修改可以通过一个wmic命令来实现目的。

echo 修改工作组
wmic computersystem where Name="%Name%" call JoinDomainOrWorkgroup Name="%Workgroup%"
wmic computersystem where Name="%ComputerName%" call JoinDomainOrWorkgroup Name="%Workgroup%"

通过修改注册表修改主机名和工作组

wmic computersystem where Name="%COMPUTERNAME%" call JoinDomainOrWorkgroup Name="%WORKGROUP%"
现在我们把它写成一个批处理,来实现无需重启修改计算机名和工作组:

echo 修改IP
::查找MAC所对应的连接名称
for /f "tokens=1,2,3,4,5,6 delims=-" %%A in ("%MAC%") do set MacWMIC=%%A:%%B:%%C:%%D:%%E:%%F
for /f "skip=2 tokens=2* delims==" %%A in ('WMIC NIC WHERE "MACAddress='%MacWMIC%' AND NetConnectionID!=NULL" GET NetConnectionID /value') do set "ConnName=%%A"
if not defined ConnName set ConnName="本地连接"
netsh interface ip set address name="%ConnName%" source=static addr=%IP% mask=%mask%
netsh interface ip set address name="%ConnName%" gateway=%gway% gwmetric=0
netsh interface ip set dns name="%ConnName%" source=static addr=%dns% register=PRIMARY
netsh interface ip add dns name="%ConnName%" addr=%dns2% index=2
netsh interface ip set wins name="%ConnName%" source=static addr=none

@echo off
echo AppLife.Net
set /p name=请输您的计算机名:
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetControlComputerNameActiveComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
echo.
echo 修改计算机名完毕
echo.
echo AppLife.Net
set /p work1=请输入您的工作组名:
wmic computersystem where Name="%COMPUTERNAME%" call JoinDomainOrWorkgroup Name="%work1%"
echo 修改工作组完毕
pause>nul
echo.

复制代码 代码如下:

echo arp绑定 %IP% %MAC%
arp -d
arp -s %IP% %MAC%
echo arp绑定网关 %gway%,如果网络不通,将使用默认网关的MAC:00-00-5e-00-01-01
ping -n 2 %gway%>nul 2>nul
if [%ERRORLEVEL%]==[1] (set GateMac=00-00-5e-00-01-01) else (
for /f "skip=3 tokens=2" %%H in ('arp -a %gway%') do set GateMac=%%H
)
cmd /c arp -s %gway% %GateMac%

 

@echo off
echo AppLife.Net
set /p name=请输您的计算机名:
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetControlComputerNameActiveComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINESystemCurrentControlSetServicesTcpipParameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
echo.
echo 修改计算机名完毕
echo.
echo AppLife.Net
set /p work1=请输入您的工作组名:
wmic computersystem where Name="%COMPUTERNAME%" call JoinDomainOrWorkgroup Name="%work1%"
echo 修改工作组完毕
pause>nul
echo.

for /l %%i in (3,-1,0) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后重启电脑……
setlocal
cd/d %temp%
echo [version] > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >> reboot.inf
echo [defaultinstall] >> reboot.inf
rundll32 setupapi,%inf% 1 %temp%reboot.inf
del reboot.inf
EXIT

不需要重启

把上面的代码保存为一个bat文件,运行就可以了。

:newset
echo 您的机器可能是新机器,需要手工输入ip
for /f "tokens=1,2 delims==" %%i in ('wmic bios get SerialNumber /value^|find "="') do set Name=%%j
if not defined Name set /p Name=请输入新机器的名字
echo 机器名:%Name%
call :select "Physical Address" "mac"
echo mac :%mac%
set /a aa=%random%%%9
set IP=168.30.7.1%aa%
set mask=255.255.0.0
set gway=168.30.1.233
set dns=168.1.4.147
set dns2=168.1.6.243
set Workgroup=vga00l
echo IP 配置: %ip% %mask% %gway% %dns% %dns2% %Workgroup%
for /l %%i in (5,-1,0) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后修改机器名……
goto Enterset

:select
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:%1') do if not "!%~2!" == "" set "%~2=%%i"
GOTO :eof

本文由美高梅网站是多少发布于美高梅-操作,转载请注明出处:window批处理修改计算机名,工作组的批处理

上一篇:没有了 下一篇:没有了
猜你喜欢
热门排行
精彩图文