重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

使用脚本更改计算机名

第一种:

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、成都小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了老城免费建站欢迎大家使用!

使用脚本更改计算机名

 

 

Dim reval
Set objnet = CreateObject ("WScript.Network")
Set R = CreateObject("WScript.Shell")
reval = InputBox ("当前的计算机名是:" & objnet.ComputerName,"输入新的计算机名")
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
err = objComputer.Rename(objnet.ComputerName)
Next

For Each objComputer in colComputers
errReturn = ObjComputer.Rename (reval)
If reval <> "" Then
                return=MsgBox ("你确定要重起计算机吗?",vbokcancel+vbexclamation,"注意!")
                If return=vbok Then
                        R.run("Shutdown.exe -r -t 0")
                End if
    End If
Next

第二种:自动改成该电脑的序列号

 

'Rename computer by serial # v1.0 November 2009
dim Bios, BiosSerial, objFSO, objTextFile
'Const ForReading = 1, ForWriting = 2, ForAppending = 8

'get serial number
for each Bios in GetObject("winmgmts:").InstancesOf ("win32_bios")
BiosSerial = Bios.SerialNumber
exit for
next

Set WshNetwork = WScript.CreateObject("WScript.Network")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
err = objComputer.Rename(BiosSerial)
Next

'messagebox
msgbox "Computername changed to " + BiosSerial + "...", yes

 

 

第三种:改成自己设置的前缀名+时间

 

@echo off
mode con cols=45 lines=8
title 计算机名更改
color f8
set f=%time:~3,-6%
set m=%time:~6,-3%
echo.
echo.
echo.
set /p name=  前缀名:
echo.
echo.
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam" /v @ /t REG_SZ /d "%name%%f%%m%" /f >nul && reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%name%%f%%m%" /f >nul && reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t REG_SZ /d "%name%%f%%m%" /f >nul && reg add "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog" /v "ComputerName" /t REG_SZ /d "%name%%f%%m%" /f >nul && reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%name%%f%%m%" /f >nul && reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d "%name%%f%%m%" /f >nul && reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "Hostname" /t REG_SZ /d "%name%%f%%m%" /f >nul
IF %ERRORLEVEL%==0 goto t
goto n
:t
echo.
echo.
echo.
echo  修改成功,要使更改生效,必须重新启动计算机.
echo.
echo.
echo.
pause
mode con cols=45 lines=8
title 系统设置改变
echo.
echo.
echo   必须重新启动计算机才能使新的设置生效。
echo.
echo   想现在就重新启动计算机吗?
echo.
echo   Y:确定   N:取消
echo.
set /p select1=请输入:
if /i "%select1%"=="Y" goto y
if /i "%select1%"=="N" goto n
:y
shutdown -r -t 0
exit
:n
exit


网页标题:使用脚本更改计算机名
分享链接:http://cqcxhl.cn/article/psshce.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP