开发者

Rename PC To Serial Number

I'm trying to make a script to rename PC's to their serial number. I'm not great with VB, but I've been able to put together enough code to READ the serial number, but I'm not sure where to WRITE it.

Here's what I currently have:

    strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strCompu开发者_JS百科ter & "\root\CIMV2")


Set colBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")

For each objBIOS in colBIOS
  WScript.Echo "SERIAL=" & objBIOS.SerialNumber
Next

Thanks in advance for any help!


You can change the computer name editing the Windows registry. use this code with extreme caution.

This code is for educational purposes only, I recommend that you use the SetComputerNameEx function and not a script to do these tasks

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")
For each objBIOS in colBIOS
StrNewPCName=objBIOS.SerialNumber
Next
Set MyShell= CreateObject ("WSCript.shell")
StrCurrentControlSet = "HKLM\SYSTEM\CurrentControlSet\"
StrTcpipParams = StrCurrentControlSet & "services\Tcpip\Parameters\"
StrComputerName = StrCurrentControlSet & "Control\ComputerName\"
With MyShell
.RegDelete StrTcpipParams & "Hostname"
.RegDelete StrTcpipParams & "NV Hostname"
.RegWrite StrComputerName & "ComputerName\ComputerName", StrNewPCName
.RegWrite StrComputerName & "ActiveComputerName\ComputerName", StrNewPCName
.RegWrite StrTcpipParams & "Hostname", StrNewPCName
.RegWrite StrTcpipParams & "NV Hostname", StrNewPCName
End With 


I doubt you can change the computer name through WMI. There is a Windows API call here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜