温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用脚本更改计算机名

发布时间:2020-07-16 00:52:23 来源:网络 阅读:1117 作者:Younisz 栏目:移动开发

第一种:

使用脚本更改计算机名

 

 

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI