Tutorial :Rename PC To Serial Number



Question:

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:\\" & strComputer & "\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!


Solution:1

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   


Solution:2

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »